Scenario 1: Local variable
class Ordin
def first
a=10
puts a
end
def second
puts a
end
end
obj=Ordin.new
obj.first
obj.second
output:
variable_explanation.rb:11:in `second’: undefined local variable or method `a’ for # (NameError)
from variable_explanation.rb:17
10
Description:
a –> works only inside of first method
———————————————-
Recent comments
1 year 23 weeks ago
1 year 23 weeks ago
1 year 25 weeks ago
1 year 27 weeks ago
1 year 42 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 46 weeks ago
1 year 48 weeks ago