Today morning i exploring the ruby 1.8.7, i found myself some what
clear so
that i worked some basic code concepts (class and methods) and i
satisfied, Again I build a
code to confuse myself. Initially it show some error, finally i made
some
modification on the code,and it works fine, but i thought it needs to
show error, can anyone please explain how it works ?
Note:
I created a class with in class it showing Error like “class definition
in
method body”, If its is means, why not in methods ?
Code:
class AdavanceConfuse
def AdavanceConfuse.Class_method1
puts “this is class_method1”
def AdavanceConfuse.class_method1_attribute_class_method
puts “this is class_method1_attribute_class_method”
end
class_method2
end
def AdavanceConfuse.class_method2
#~ class TestClass
puts “this is class_method2”
def Instance_method1
puts “this is instance_method1”
end
#~ end
end
end
I created a class with in class it showing Error like “class definition
in method body”,
“”""""""""“If its is means, why not in methods ?”""""""""""
May be my question is wrong ? can u please tell me how to call method
defined within method of class ?
“”"""
def AdavanceConfuse.Class_method1
puts “this is class_method1”
def AdavanceConfuse.class_method1_attribute_class_method
puts “this is class_method1_attribute_class_method”
end
end
“”""""
How to call the class_method1_attribute_class_method in the above code
and how it internally ,the request will be handled in ruby ?
How i can access a class’ method defined with in class ?
Example:
class AdavanceConfuse
class AnotherClass
def AnotherClass.method1
puts “Class with in class’s class method”
end
end
end
How to call the method “method1”,how it internally ,the request will be
handled in ruby ?
May be my question is wrong ? can u please tell me how to call method
defined within method of class ?
You know it already, don’t you? Please look at your code.
and how it internally ,the request will be handled in ruby ?
It’s just defined and called like any other class method. The only
difference with nested definitions is the point in time when the
method is created (i.e. not when the interpreter executes the class
definition but when someone calls the method containing the
definition).
How i can access a class’ method defined with in class ?