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.
12 13 14 |
# File 'lib/fattr.rb', line 12 def initialize(*args, &block) super(*args, &block) end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
10 11 12 |
# File 'lib/fattr.rb', line 10 def object @object end |
Instance Method Details
#<<(element) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/fattr.rb', line 16 def << element super self ensure uniq! index! end |
#for(object) ⇒ Object
49 50 51 52 |
# File 'lib/fattr.rb', line 49 def for(object) @object = object self end |
#include?(element) ⇒ Boolean
29 30 31 32 |
# File 'lib/fattr.rb', line 29 def include?(element) @index ||= Hash.new @index[element.to_s] ? true : false end |
#index! ⇒ Object
24 25 26 27 |
# File 'lib/fattr.rb', line 24 def index! @index ||= Hash.new each{|element| @index[element.to_s] = true} end |
#initializers ⇒ Object
34 35 36 |
# File 'lib/fattr.rb', line 34 def initializers @initializers ||= Hash.new end |
#to_h ⇒ Object
45 46 47 |
# File 'lib/fattr.rb', line 45 def to_h to_hash end |
#to_hash ⇒ Object
38 39 40 41 42 43 |
# File 'lib/fattr.rb', line 38 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 |