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



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

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
      return self
    }
  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
47
# 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
      return self
    }
  end
end