Class: EasyStruct

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/easy_struct.rb

Overview

a object via snake_case when it is camelCase

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object



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

def method_missing(method, *args, &blk)
  (/(?<name>.+?)(?<setter>=)?$/ =~ method.to_s)
  property = name.camelcase(:lower).to_sym
  if @table.has_key?(property)
    setter ? @table[property] = args.first : @table[property]
  else
    super
  end
end