Skip to content

Instantly share code, notes, and snippets.

@octosteve
Created April 22, 2014 16:30
Show Gist options
  • Select an option

  • Save octosteve/11185679 to your computer and use it in GitHub Desktop.

Select an option

Save octosteve/11185679 to your computer and use it in GitHub Desktop.
>> [*1..100].reject{|num| num.odd?}
=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]
>> [*1..100].reject(&:odd?)
=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]
>> odd_proc = &:odd?
SyntaxError: (irb):43: syntax error, unexpected &
odd_proc = &:odd?
^
from /Users/StevenNunez/.rubies/ruby-2.1.1/bin/irb:11:in `<main>'
>> odd_proc = :odd?.to_proc
=> #<Proc:0x007fd93909ac80>
>> odd_proc.call
ArgumentError: no receiver given
from (irb):45:in `call'
from (irb):45
from /Users/StevenNunez/.rubies/ruby-2.1.1/bin/irb:11:in `<main>'
>> odd_proc.call(1)
=> true
>> odd_proc.call(2)
=> false
>> [*1..100].reject(&:odd?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment