Class: Whereby::Element
- Inherits:
-
Object
- Object
- Whereby::Element
- Defined in:
- lib/whereby/element.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Element
constructor
A new instance of Element.
- #to_h ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Element
Returns a new instance of Element.
3 4 5 6 |
# File 'lib/whereby/element.rb', line 3 def initialize(attrs = {}) # Only set attributes if the method exists attrs.each{ |k,v| send("#{k.whereby_underscore}=", v) if respond_to?(k.whereby_underscore.to_s) } end |
Instance Method Details
#to_h ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/whereby/element.rb', line 8 def to_h Hash[ *instance_variables.map do |variable| name = variable[1..-1].to_sym #Removing @ [name, instance_variable_get(variable)] end.flatten ] end |