Skip to content

Instantly share code, notes, and snippets.

@shivabhusal
Last active June 21, 2017 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivabhusal/5645be4ea9992c392f6a1b2342acd2b0 to your computer and use it in GitHub Desktop.
Save shivabhusal/5645be4ea9992c392f6a1b2342acd2b0 to your computer and use it in GitHub Desktop.
class defn code is similar to normal code, but there is a little bit difference
3.times do
class A
puts "Class opened"
end
end
# => Class opened
# => Class opened
# => Class opened
# but there is little bit difference
3.times do |i|
class A
puts "Class opened #{i+1}th time"
end
end
# Error
# `<class:A>': undefined local variable or method `i' for A:Class (NameError)
# This is however possible
3.times do|i|
puts "#{i+1}th time"
class A
puts "Class opened"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment