Class: Glassfrog::Base
Overview
Superclass of all GlassFrog classes.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Check equality between two objects.
-
#hashify ⇒ Hash
Turns the Base object into a hash.
-
#initialize(attrs = {}) {|_self| ... } ⇒ Glassfrog::Base
constructor
Initializes a new Base object.
Methods included from Utils
#extract_id, #parameterize, #symbolize_keys
Constructor Details
#initialize(attrs = {}) {|_self| ... } ⇒ Glassfrog::Base
Initializes a new Base object.
17 18 19 20 21 22 |
# File 'lib/glassfrog/base.rb', line 17 def initialize(attrs = {}) attrs.each do |key, value| instance_variable_set("@#{key}", value); end yield(self) if block_given? end |
Instance Attribute Details
#id ⇒ Integer
10 11 12 |
# File 'lib/glassfrog/base.rb', line 10 def id @id end |
Instance Method Details
#==(other) ⇒ Boolean
Check equality between two objects. Should be equal if they are the same type and their IDs are also equal.
29 30 31 |
# File 'lib/glassfrog/base.rb', line 29 def ==(other) self.id == other.id && self.class == other.class end |
#hashify ⇒ Hash
Turns the Base object into a hash.
37 38 39 40 41 |
# File 'lib/glassfrog/base.rb', line 37 def hashify hash = Hash.new self.instance_variables.each { |var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) } symbolize_keys(hash) end |