Class: Fattr::List
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #for(object) ⇒ Object
- #include?(element) ⇒ Boolean
- #index! ⇒ Object
-
#initialize(*args, &block) ⇒ List
constructor
A new instance of List.
- #initializers ⇒ Object
- #to_h ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ List
Returns a new instance of List.
9 10 11 |
# File 'lib/fattr.rb', line 9 def initialize(*args, &block) super(*args, &block) end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
7 8 9 |
# File 'lib/fattr.rb', line 7 def object @object end |
Instance Method Details
#<<(element) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/fattr.rb', line 13 def << element super self ensure uniq! index! end |
#for(object) ⇒ Object
46 47 48 49 |
# File 'lib/fattr.rb', line 46 def for(object) @object = object self end |
#include?(element) ⇒ Boolean
26 27 28 29 |
# File 'lib/fattr.rb', line 26 def include?(element) @index ||= Hash.new @index[element.to_s] ? true : false end |
#index! ⇒ Object
21 22 23 24 |
# File 'lib/fattr.rb', line 21 def index! @index ||= Hash.new each{|element| @index[element.to_s] = true} end |
#initializers ⇒ Object
31 32 33 |
# File 'lib/fattr.rb', line 31 def initializers @initializers ||= Hash.new end |
#to_h ⇒ Object
42 43 44 |
# File 'lib/fattr.rb', line 42 def to_h to_hash end |
#to_hash ⇒ Object
35 36 37 38 39 40 |
# File 'lib/fattr.rb', line 35 def to_hash if @object list = @object.class.fattrs + @object.fattrs list.inject(Hash.new){|hash, fattr| hash.update(fattr => @object.send(fattr))} end end |