summaryrefslogtreecommitdiffhomepage
path: root/mrblib/struct.rb
diff options
context:
space:
mode:
authormimaki <[email protected]>2012-04-20 09:39:03 +0900
committermimaki <[email protected]>2012-04-20 09:39:03 +0900
commite0d6430f63c4cbe0c71ce82ee23284671389a818 (patch)
tree41abad7f12eced98d9ac14d141cea62464c3332f /mrblib/struct.rb
parent54ad561098ed353ada70205c39b2c42a2a2eb9e5 (diff)
downloadmruby-e0d6430f63c4cbe0c71ce82ee23284671389a818.tar.gz
mruby-e0d6430f63c4cbe0c71ce82ee23284671389a818.zip
add mruby sources
Diffstat (limited to 'mrblib/struct.rb')
-rw-r--r--mrblib/struct.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/mrblib/struct.rb b/mrblib/struct.rb
new file mode 100644
index 000000000..b11f59f2a
--- /dev/null
+++ b/mrblib/struct.rb
@@ -0,0 +1,30 @@
+#
+# Struct
+#
+class Struct
+ # 15.2.18.4.4
+ def each(&block)
+ self.class.members.each{|field|
+ block.call(self[field])
+ }
+ self
+ end
+
+ # 15.2.18.4.5
+ def each_pair(&block)
+ self.class.members.each{|field|
+ block.call(field.to_sym, self[field])
+ }
+ self
+ end
+
+ # 15.2.18.4.7
+ def select(&block)
+ ary = []
+ self.class.members.each{|field|
+ val = self[field]
+ ary.push(val) if block.call(val)
+ }
+ ary
+ end
+end