Skip to content

Instantly share code, notes, and snippets.

@DylanFM
Created November 11, 2008 03:41
Show Gist options
  • Save DylanFM/23733 to your computer and use it in GitHub Desktop.
Save DylanFM/23733 to your computer and use it in GitHub Desktop.
i, @i = 1, 1
def add_one(i)
i =+1
end
add_one(i)
add_one(i)
add_one(i)
puts i #=> 1
def add_one(i)
@i = i+1
end
add_one(@i)
add_one(@i)
add_one(@i)
puts @i #=> 4
i, @i = 1, 1
def add_one(i, &block)
i = i+1
yield i
end
add_one(i) { |i| i = i*5 }
puts i #=> 10
add_one(@i) { |i| @i = i*5 }
puts @i #=> 10
i, @i = 1, 1
def add_one(i, &block)
@i = i+1
yield i
end
add_one(i) { |i| i = i*5 }
puts i #=> 5
add_one(@i) { |i| @i = i*5 }
puts @i #=> 10
i, @i = 1, 1
class Numeric
def add_one
self + 1
end
end
1..40.times do
i = i.add_one
end
puts i #=> 41
1..40.times do
@i = @i.add_one
end
puts @i #=> 41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment