Module: Nyaplot::Jsonizable::ClassMethod

Defined in:
lib/nyaplot/base.rb

Instance Method Summary collapse

Instance Method Details

#define_group_properties(name, symbols) ⇒ Object

Define getter/setter for each property and group. Grouped properties will be merged into one parameter when running to_json.

Examples:

define_group_properties(:options, [:hoge, :nya]) #The methods :options, :hoge, :nya are defined
options({})
hoge(3)
nya(4)
some_instance.to_json #-> {options:{hoge: 3, nya:4}}

Parameters:

  • name (Symbol)

    Group name

  • symbols (Symbol)

    Name for each property



58
59
60
61
62
63
64
65
66
# File 'lib/nyaplot/base.rb', line 58

def define_group_properties(name, symbols)
  define_properties(name)
  symbols.each do |symbol|
    define_method(symbol) {|val=nil|
      return @properties[name][symbol] if val.nil?
      @properties[name][symbol] = val
    }
  end
end

#define_properties(*symbols) ⇒ Object

Define getter/setter for each property

Parameters:

  • symbols (Symbol)

    Name for each property



39
40
41
42
43
44
45
46
# File 'lib/nyaplot/base.rb', line 39

def define_properties(*symbols)
  symbols.each do |symbol|
    define_method(symbol) {|val=nil|
      return @properties[symbol] if val.nil?
      @properties[symbol] = val
    }
  end
end