I am trying to find out if there is any equivalence to what I see in Groovy as ExpandoMetaClasses . I read about Open Classes , but I can't figure out what level of Ruby coverage allows me to change a class.
Borrowing the example from the blog above in Groovy, I could modify the Java String class and add a method to it as follows:
String.metaClass.shout = {->
return delegate.toUpperCase()
}
println "Hello MetaProgramming".shout()
And I think that Ruby would force you to override the class and possibly its alias (please help clarify my misunderstandings at this point):
class String
def foo
"foo"
end
end
puts "".foo
There are ways in Groovy to override the basic methods of the Java library for individual instances or for a group of instances using categories that are similar to what I would call mixins in Ruby.
?
, - , - .rb , ?
, Ruby, Groovy, , .