summaryrefslogtreecommitdiffhomepage
path: root/mrblib/struct.rb
diff options
context:
space:
mode:
authorPaolo Bosetti <[email protected]>2012-08-06 15:02:03 +0200
committerPaolo Bosetti <[email protected]>2012-08-06 15:02:56 +0200
commitaa0d2f91447c49363059f2e95cb9023f65a6fbef (patch)
tree2cfa325956e62648f2161564adfdf6dddc45b737 /mrblib/struct.rb
parentfd097b8aff7b91bd105fc1daec5a4050a947b763 (diff)
parent193c98ae540d43d082795fd77ea81a4f6f7fd0f6 (diff)
downloadmruby-aa0d2f91447c49363059f2e95cb9023f65a6fbef.tar.gz
mruby-aa0d2f91447c49363059f2e95cb9023f65a6fbef.zip
Updated Xcode project build settings in conformity with 10.8/Xcode 4.4
Diffstat (limited to 'mrblib/struct.rb')
-rw-r--r--mrblib/struct.rb78
1 files changed, 41 insertions, 37 deletions
diff --git a/mrblib/struct.rb b/mrblib/struct.rb
index 4b6d767a9..5d0ede90f 100644
--- a/mrblib/struct.rb
+++ b/mrblib/struct.rb
@@ -2,45 +2,49 @@
# Struct
#
# ISO 15.2.18
-class Struct
- ##
- # Calls the given block for each element of +self+
- # and pass the respective element.
- #
- # ISO 15.2.18.4.4
- def each(&block)
- self.class.members.each{|field|
- block.call(self[field])
- }
- self
- end
+if Object.const_defined?(:Struct)
+ class Struct
- ##
- # Calls the given block for each element of +self+
- # and pass the name and value of the respectiev
- # element.
- #
- # ISO 15.2.18.4.5
- def each_pair(&block)
- self.class.members.each{|field|
- block.call(field.to_sym, self[field])
- }
- self
- end
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the respective element.
+ #
+ # ISO 15.2.18.4.4
+ def each(&block)
+ self.class.members.each{|field|
+ block.call(self[field])
+ }
+ self
+ end
- ##
- # Calls the given block for each element of +self+
- # and returns an array with all elements of which
- # block is not false.
- #
- # ISO 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
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the name and value of the respectiev
+ # element.
+ #
+ # ISO 15.2.18.4.5
+ def each_pair(&block)
+ self.class.members.each{|field|
+ block.call(field.to_sym, self[field])
+ }
+ self
+ end
+
+ ##
+ # Calls the given block for each element of +self+
+ # and returns an array with all elements of which
+ # block is not false.
+ #
+ # ISO 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
end
+