Class: OpenStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/ostructfixed.rb

Direct Known Subclasses

Templater::Variables

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.with(&block) ⇒ Object



14
15
16
17
18
# File 'lib/ostructfixed.rb', line 14

def self.with(&block)
	struct = new
	struct.instance_eval(&block)
	struct
end

Instance Method Details

#[](field) ⇒ Object

Get the field by its name, faster than #send and with dynamic field names more convenient.



22
23
24
# File 'lib/ostructfixed.rb', line 22

def [](field)
	@table[field.to_sym]
end

#[]=(field, value) ⇒ Object

Assign a field by its name, faster than #send and with dynamic fields more convenient



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

def []=(field,value)
	new_ostruct_member(field)
	@table[field.to_sym] = value
end

#__hash__Object

Get the internal hash-table.



39
40
41
# File 'lib/ostructfixed.rb', line 39

def __hash__
	@table
end

#to_hashObject

Get a copy of the table with the members.



34
35
36
# File 'lib/ostructfixed.rb', line 34

def to_hash
	@table.dup
end