Class: SuperStruct

Inherits:
OpenStruct
  • Object
show all
Includes:
Enumerable
Defined in:
lib/super_struct.rb

Overview

Code shamelessly stolen from errtheblog.com/post/30

Direct Known Subclasses

Flickry::Base

Instance Method Summary collapse

Instance Method Details

#[](member) ⇒ Object



24
25
26
# File 'lib/super_struct.rb', line 24

def [](member)
  send(member)
end

#[]=(member, value) ⇒ Object



28
29
30
# File 'lib/super_struct.rb', line 28

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

#eachObject



10
11
12
13
14
15
# File 'lib/super_struct.rb', line 10

def each
  members.each do |method|
    yield send(method)
  end
  self
end

#each_pairObject



17
18
19
20
21
22
# File 'lib/super_struct.rb', line 17

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

#membersObject



6
7
8
# File 'lib/super_struct.rb', line 6

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