Module: Liner::Hashable
- Defined in:
- lib/liner/hashable.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Read a liner attribute.
-
#[]=(key, value) ⇒ Object
Set a liner attribute.
-
#liner ⇒ Hash
Build a hash of liner attributes.
-
#liner=(hash) ⇒ Hash
Set multiple attribute values.
-
#liner_values=(values) ⇒ Array
Set mulitple attribute values.
-
#to_h ⇒ Hash
(also: #to_hash)
Get a hash of attributes.
Instance Method Details
#[](key) ⇒ Object
Read a liner attribute
8 9 10 11 12 |
# File 'lib/liner/hashable.rb', line 8 def [](key) send key.to_sym rescue NoMethodError liner_get key end |
#[]=(key, value) ⇒ Object
Set a liner attribute
19 20 21 22 23 |
# File 'lib/liner/hashable.rb', line 19 def []=(key,value) send :"#{key}=", value rescue NoMethodError liner_set key, value end |
#liner ⇒ Hash
Build a hash of liner attributes
28 29 30 |
# File 'lib/liner/hashable.rb', line 28 def liner liner_keys.inject({}) { |h,k| h[k] = self[k]; h }.freeze end |
#liner=(hash) ⇒ Hash
Set multiple attribute values
36 37 38 |
# File 'lib/liner/hashable.rb', line 36 def liner=(hash) hash.each { |k,v| self[k] = hash[k] } end |
#liner_values=(values) ⇒ Array
Set mulitple attribute values
44 45 46 47 48 |
# File 'lib/liner/hashable.rb', line 44 def liner_values=(values) values.each_with_index do |value, i| self[liner_keys[i]] = value end end |
#to_h ⇒ Hash Also known as: to_hash
Get a hash of attributes
53 54 55 |
# File 'lib/liner/hashable.rb', line 53 def to_h liner.dup end |