Skip to content
Recordx is similar to Openstruct except it sends a message to a RecordX designated object when a field is updated
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
MIT-LICENSE
README.md
gem-public_cert.pem
recordx.gemspec

README.md

Introducing the RecordX gem

The RecordX gem is a convenient way of storing names and values accessible from either the hash syntax or the method syntax e.g.

require 'recordx'

rec = RecordX.new()
rec.to_h #=> {}

rec.fruit = 'apple'
rec.to_h #=> {:fruit=>"apple"}

rec.h[:fruit] = 'banana'
rec.to_h #=> {:fruit=>"banana"}
rec.day = 'Sunday' #=> {:fruit=>"banana", :day=>"Sunday"}

It can also use a hash passed in when the object is initialised e.g.

rec = RecordX.new({car: 'electric', country: 'France'})
puts "I would like to drive the #{rec.car} car in #{rec.country}"
#=> I would like to drive the electric car in France

The RecordX object can be embedded within a consumer object and will notify it when a record value has changed e.g.

class Fun

  def record()
    RecordX.new({time: 'morning', day: 'Friday'}, self, id='100')
  end

  def update(id='', key_pair)
    puts "ready to update record '%s' using name '%s' and value '%s'" % \
      ([id] + key_pair.to_a.first)
  end
end

fun = Fun.new
rec = fun.record
puts rec.day #=> 'Friday'
rec.day = 'Saturday'
puts rec.day #=> 'Saturday'

Resources

Something went wrong with that request. Please try again.