Accessor methods let you “set” or “get” instance variables belonging to an object. Most Java programmers are introduced to getters and setters very early in their OOP education. Lines of code might not be a reliable metric to compare programming languages but nevertheless below is a simple example for creating getters and setters in both Java and Ruby :
Java ->
public class Getset
{
private int value;
public void setValue(int n)
{
value = n;
}
public int getValue()
{
return value;
}
}
Ruby->
class Getset attr_accessor :value end
Thats, so sexy about ruby.
I’ve recently started working on ruby. What the hell all the programmers were think till now? I mean, why ruby hasn’t been popular before outside of Japan?
Indeed many programmers seems to be unaware of how cool and efficient it is. I think these days Rails is gaining popularity but then that is only *one* killer application of Ruby…there are a lot of other awesome open source projects powered by Ruby!
Sweet blog. I never know what I am going to come across next. I think you should do more posting as you have some pretty intelligent stuff to say.
I’ll be watching you .