each_pair()
public
Calls block once for each instance
variable, passing the name (as a symbol) and the value as parameters.
Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.each_pair {|name, value| puts("#{name} => #{value}") }
produces:
name => Joe Smith
address => 123 Maple, Anytown NC
zip => 12345
Show source
/*
* call-seq:
* struct.each_pair {|sym, obj| block } => struct
*
* Calls <i>block</i> once for each instance variable, passing the name
* (as a symbol) and the value as parameters.
*
* Customer = Struct.new(:name, :address, :zip)
* joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
* joe.each_pair {|name, value| puts("#{name} => #{value}") }
*
* <em>produces:</em>
*
* name => Joe Smith
* address => 123 Maple, Anytown NC
* zip => 12345
*/
static VALUE
rb_struct_each_pair(s)
VALUE s;
{
VALUE members;
long i;
members = rb_struct_members(s);
for (i=0; i<RSTRUCT(s)->len; i++) {
rb_yield_values(2, rb_ary_entry(members, i), RSTRUCT(s)->ptr[i]);
}
return s;
}