Class: CyberarmEngine::Style

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberarm_engine/ui/style.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Style

Returns a new instance of Style.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cyberarm_engine/ui/style.rb', line 22

def initialize(hash = {})
  h = hash
  # h = Marshal.load(Marshal.dump(hash))

  h[:default] = {}

  h.each do |key, value|
    next if value.is_a?(Hash)

    h[:default][key] = value
  end

  @hash = h
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cyberarm_engine/ui/style.rb', line 37

def method_missing(method, *args)
  if method.to_s.end_with?("=")
    raise "Did not expect more than 1 argument" if args.size > 1

    @hash[method.to_s.sub("=", "").to_sym] = args.first

  elsif args.empty?
    @hash[method]
  else
    raise ArgumentError, "Did not expect arguments"
  end
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



20
21
22
# File 'lib/cyberarm_engine/ui/style.rb', line 20

def hash
  @hash
end