Method: Struct#each
- Defined in:
- struct.c
#each {|value| ... } ⇒ self #each ⇒ Object
Calls the given block with the value of each member; returns self
:
Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.each {|value| p value }
Output:
"Joe Smith"
"123 Maple, Anytown NC"
12345
Returns an Enumerator if no block is given.
Related: #each_pair.
890 891 892 893 894 895 896 897 898 899 900 |
# File 'struct.c', line 890 static VALUE rb_struct_each(VALUE s) { long i; RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size); for (i=0; i<RSTRUCT_LEN(s); i++) { rb_yield(RSTRUCT_GET(s, i)); } return s; } |