Module: Twilio::Resource

Included in:
Account, Call, SMS
Defined in:
lib/twilio/resource.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args, &blk) ⇒ Object (private)

:nodoc



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/twilio/resource.rb', line 29

def method_missing(id, *args, &blk) #:nodoc
  meth = id.to_s
  if meth =~ /\=$/
    add_attr_writer meth
    send meth, args.first
  elsif meth =~ /^#{meth}\?/i
    add_predicate meth
    send meth
  elsif self[id]
    add_attr_reader meth
    send meth
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object

Convenience for accessing attributes. Attributes can be accessed either using the preferred symbol style, e.g. :if_machine or using the Twilio stringified attribute style, e.g. ‘IfMachine’ Kind of like ActiveSupport::HashWithIndifferentAccess on crack.



9
10
11
12
# File 'lib/twilio/resource.rb', line 9

def [](key)
  accessor = key.is_a?(Symbol) ? key.to_s.camelize : key
  attributes[accessor]
end

#[]=(key, value) ⇒ Object



14
15
16
17
# File 'lib/twilio/resource.rb', line 14

def []=(key,value)
  accessor = key.is_a?(Symbol) ? key.to_s.camelize : key
  attributes[accessor] = value
end