Last active
June 21, 2017 16:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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