Module: Titi::Adaptor
- Included in:
- Provider::ActivityStreams::ActivityStreamsStruct
- Defined in:
- lib/titi/adaptor.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#adapt(*args) {|_self| ... } ⇒ Object
Adopt attributes from given hash, and programatically-set attributes from block.
-
#attributes=(hsh) ⇒ Object
for each key in hsh, sets that attribute to the corresponding value.
Class Method Details
.included(base) ⇒ Object
55 56 57 58 59 |
# File 'lib/titi/adaptor.rb', line 55 def self.included base base.class_eval do extend Titi::Adaptor::ClassMethods end end |
Instance Method Details
#adapt(*args) {|_self| ... } ⇒ Object
Adopt attributes from given hash, and programatically-set attributes from block
37 38 39 40 41 42 |
# File 'lib/titi/adaptor.rb', line 37 def adapt *args, &block hsh = args. args_hsh = Hash.zip(self.members[0...args.length], args) self.attributes = hsh.merge(args_hsh) yield self if block end |
#attributes=(hsh) ⇒ Object
for each key in hsh, sets that attribute to the corresponding value.
11 12 13 14 15 16 |
# File 'lib/titi/adaptor.rb', line 11 def attributes= hsh hsh.each do |attr, val| setter = "#{attr}=" self.send(setter, val) if respond_to?(setter) end end |