Skip to content

Instantly share code, notes, and snippets.

@fellipebrito
Last active August 29, 2015 14:10
Show Gist options
  • Save fellipebrito/fbc3e3ca22ec1d25273d to your computer and use it in GitHub Desktop.
Save fellipebrito/fbc3e3ca22ec1d25273d to your computer and use it in GitHub Desktop.
2.1.5 :011 > 'begin' <=> 'end'
=> -1
2.1.5 :012 > 'same' <=> 'same'
=> 0
2.1.5 :013 > a = [5, 3, 4, 1]
=> [5, 3, 4, 1]
2.1.5 :014 > a.sort
=> [1, 3, 4, 5]
2.1.5 :015 > a.any? {|i| i > 6}
=> false
2.1.5 :016 > a.any? {|i| i > 4}
=> true
2.1.5 :017 > a.all? {|i| i > 4}
=> false
2.1.5 :018 > a.all? {|i| i > 0}
=> true
2.1.5 :019 > a.collect {|i| i * 2}
=> [10, 6, 8, 2]
2.1.5 :020 > a.select {|i| i % 2 == 0} # even
=> [4]
2.1.5 :021 > a.select {|i| i % 2 == 1} # odd
=> [5, 3, 1]
2.1.5 :022 > a.max
=> 5
2.1.5 :023 > a.member?(2)
=> false
2.1.5 :024 > a.inject {|sum_code_block, i| sum_code_block + i}
=> 13
2.1.5 :025 > a.inject {|product_code_block, i| product_code_block * i}
=> 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment