Method: Net::LDAP::Entry#method_missing

Defined in:
lib/net/ldap/entry.rb

#method_missing(*args, &block) ⇒ Object

– Convenience method to convert unknown method names to attribute references. Of course the method name comes to us as a symbol, so let’s save a little time and not bother with the to_s.downcase two-step. Of course that means that a method name like mAIL won’t work, but we shouldn’t be encouraging that kind of bad behavior in the first place. Maybe we should thow something if the caller sends arguments or a block…


142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/net/ldap/entry.rb', line 142

def method_missing *args, &block # :nodoc:
  s = args[0].to_s.downcase.intern
  if attribute_names.include?(s)
    self[s]
  elsif s.to_s[-1] == 61 and s.to_s.length > 1
    value = args[1] or raise RuntimeError.new( "unable to set value" )
    value = [value] unless value.is_a?(Array)
    name = s.to_s[0..-2].intern
    self[name] = value
  else
    raise NoMethodError.new( "undefined method '#{s}'" )
  end
end