In the process of developing my own library, I’ve been reading various Ruby libraries on Github for understanding common idioms. One library I’ve been referencing (found here), leverages what I’d call an “unattached send method”. Here’s the code:
module AngellistApi
class API
attr_accessor *Configuration::VALID_OPTIONS_KEYS
# Creates a new API
def initialize(options={})
options = AngellistApi.options.merge(options)
Configuration::VALID_OPTIONS_KEYS.each do |key|
send("#{key}=", options[key])
end
end
end
end
All documentation I can find online regarding the send method in Ruby, describes it as a way of calling a method of an object via a string or symbol. However all examples have the send method attache to the object, e.g.:
object.send(:method_name, argument1)
What happens when it isn’t attached to an object? In this case is it calling the methods for the class that it’s called within? Can someone explain this code for me? 🙂
As it occurs inside an instance method, the implied object here is
self.