# o = DynamicClass.new a: 'b' # o.a -> 'b' # o.b -> raises error class DynamicClass def initialize data, &block @data = data @block = block if block end def method_missing m, *args, &block key = m.to_s.sub('=','').to_sym unless @data.has_key?(key) raise ArgumentError.new('Key :%s not found in DynamicOptions' % key) end if m.to_s.include?('=') @data[key] = args[0] else @data[key] end end end