Semicolon in object variable name
Posted
by milkfilk
on Stack Overflow
See other posts from Stack Overflow
or by milkfilk
Published on 2010-06-17T20:44:27Z
Indexed on
2010/06/17
21:03 UTC
Read the original article
Hit count: 227
There's a common LDAP attribute called userCertificate;binary. It actually has a semi-colon in the attribute name. In ruby, I turn an LDAP entry into a OpenStruct object called 'struct'.
>> struct.class => OpenStruct
But of course ruby thinks it's an end-of-line character.
?> struct.userCertificate;binary NameError: undefined local variable or method `binary' for main:Object from (irb):52 from :0
IRB knows that the local variable is there, because it gives me struct.userCertificate;binary
from the tab auto-completion. I can also see the class variable when calling struct.methods on it.
>> struct.methods => ... "send", "methods", "userCertificate;binary=", "hash", ...
It's definitely there, I can see the contents if I print the whole variable to_s(). But how can I access the local variable when it has a semicolon in it? I have workarounds for this but I thought it was an interesting problem to post.
© Stack Overflow or respective owner