Class: Okao::Emoticon

Inherits:
Object
  • Object
show all
Defined in:
lib/okao/emoticon.rb

Class Method Summary collapse

Class Method Details

.init(okaos) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/okao/emoticon.rb', line 4

def init(okaos)
  okaos.each_with_index do |face, index|
    var_name = "@face#{index}"
    instance_variable_set(var_name, face)

    define_singleton_method(var_name[1..-1]) do
      instance_variable_get(var_name)
    end
  end
end

.to_hObject



15
16
17
18
19
20
21
# File 'lib/okao/emoticon.rb', line 15

def to_h
  instance_variables.reduce({}) do |acc, cur|
    var_name = cur.to_s[1..-1]
    hash = { var_name.to_sym => self.send(var_name) }
    acc.merge(hash)
  end
end