Class: OpenStruct

Inherits:
Object show all
Defined in:
lib/lite/ruby/open_struct.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



7
8
9
# File 'lib/lite/ruby/open_struct.rb', line 7

def attributes
  @table
end

#replace(args) ⇒ Object



11
12
13
# File 'lib/lite/ruby/open_struct.rb', line 11

def replace(args)
  args.each { |key, val| self[key] = val }
end

#to_hash(table: true) ⇒ Object Also known as: to_h



15
16
17
18
19
# File 'lib/lite/ruby/open_struct.rb', line 15

def to_hash(table: true)
  return attributes unless table

  { table: attributes }
end

#to_json(table: true) ⇒ Object Also known as: as_json



21
22
23
# File 'lib/lite/ruby/open_struct.rb', line 21

def to_json(table: true)
  to_hash(table: table).to_json
end