Sha256: d5b48cf1bc29308bb567d033e3db9eba41083d073197a1e751ff8f98197ddc88

Contents?: true

Size: 504 Bytes

Versions: 6

Compression:

Stored size: 504 Bytes

Contents

require 'ostruct'
# Code shamelessly stolen from http://errtheblog.com/post/30
class SuperStruct < OpenStruct
  include Enumerable

  def members
    methods(false).grep(/=/).map { |m| m[0...-1] }
  end

  def each
    members.each do |method|
      yield send(method)
    end
    self
  end
  
  def each_pair
    members.each do |method|
      yield method, send(method)
    end
    self
  end
  
  def [](member)
    send(member)
  end

  def []=(member, value)
    send("#{member}=", value)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wideopenspaces-flickry-0.1.2 lib/super_struct.rb
wideopenspaces-flickry-0.1.3 lib/super_struct.rb
wideopenspaces-flickry-0.1.5 lib/super_struct.rb
wideopenspaces-flickry-0.1.6 lib/super_struct.rb
wideopenspaces-flickry-0.2.0 lib/super_struct.rb
wideopenspaces-flickry-0.2.1 lib/super_struct.rb