有一個稱爲userCertificate; binary的常見LDAP屬性。它實際上在屬性名稱中有一個分號。在ruby中,我將一個LDAP條目轉換爲一個名爲'struct'的OpenStruct對象。對象變量名稱中的分號
>> struct.class => OpenStruct
但當然,紅寶石認爲這是一個行尾字符。
?> struct.userCertificate;binary NameError: undefined local variable or method `binary' for main:Object from (irb):52 from :0
IRB知道,局部變量是存在的,因爲它給了我struct.userCertificate;binary
從標籤自動完成。調用struct.methods時,我也可以看到類變量。
>> struct.methods => ... "send", "methods", "userCertificate;binary=", "hash", ...
它絕對存在,如果我打印整個變量to_s(),我可以看到內容。但是如何訪問局部變量,當它有一個分號?我有這方面的解決方法,但我認爲這是一個有趣的問題發佈。
這工作就像一個冠軍。謝謝。 – squarism 2010-06-18 02:34:46