Module: ZerigoDNS::Resource::Attributes::InstanceMethods
- Defined in:
- lib/zerigodns/resource/attributes.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Object
Initialize a new resource.
-
#method_missing(mtd, *args) ⇒ Object
Allows method-style access to the attributes.
-
#to_hash ⇒ Hash
Converts the resource to a hash.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mtd, *args) ⇒ Object
Allows method-style access to the attributes.
10 11 12 13 14 15 16 17 18 |
# File 'lib/zerigodns/resource/attributes.rb', line 10 def method_missing mtd, *args if mtd.to_s.chars.to_a.last == '=' raise ArgumentError, "Invalid number of arguments (#{args.length} for 1)" if args.length != 1 attributes[mtd.to_s.slice(0,mtd.to_s.length-1)] = args.first else raise ArgumentError, "Invalid number of arguments (#{args.length} for 0)" if args.length != 0 attributes[mtd.to_s] end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/zerigodns/resource/attributes.rb', line 6 def attributes @attributes end |
Instance Method Details
#initialize(attributes = {}) ⇒ Object
Initialize a new resource
28 29 30 31 |
# File 'lib/zerigodns/resource/attributes.rb', line 28 def initialize attributes={} @attributes = {} merge_attributes attributes end |
#to_hash ⇒ Hash
Converts the resource to a hash
22 23 24 |
# File 'lib/zerigodns/resource/attributes.rb', line 22 def to_hash attributes end |