gak
08-18-2007, 02:40 PM
Hi
I'm new to Ruby but have some experience in Java. To try and get to grips with Ruby I've been playing around with it and trying to make some old classes I wrote in Java to work in Ruby.
This is a bare-bones class I wrote in Java:
public class Helper {
//attributes
private String name;
private String address;
private String telephone;
public Helper(String name, String address, String telephone) {
//constuctor
this.name = name;
this.address = address;
this.telephone = telephone;
}
//Followed by appropriate getter/setters and methods/main() etc.
This is what I done so far in Ruby and seems to work:
class Helper
attr_accessor :name, :address, :telephone
def initialize (name, address, telephone)
@name = name
@address = address
@telephone = telephone
end
end
The part that is confusing me is making the attributes private as in my Java code, and then doing the suitable getter/setter methods to go with it. I'm not sure how to lay the code out?
If anyone could offer some advice or point me in the direction of a good newbie guide, I'd be much abliged!
Many thanks
Gak
I'm new to Ruby but have some experience in Java. To try and get to grips with Ruby I've been playing around with it and trying to make some old classes I wrote in Java to work in Ruby.
This is a bare-bones class I wrote in Java:
public class Helper {
//attributes
private String name;
private String address;
private String telephone;
public Helper(String name, String address, String telephone) {
//constuctor
this.name = name;
this.address = address;
this.telephone = telephone;
}
//Followed by appropriate getter/setters and methods/main() etc.
This is what I done so far in Ruby and seems to work:
class Helper
attr_accessor :name, :address, :telephone
def initialize (name, address, telephone)
@name = name
@address = address
@telephone = telephone
end
end
The part that is confusing me is making the attributes private as in my Java code, and then doing the suitable getter/setter methods to go with it. I'm not sure how to lay the code out?
If anyone could offer some advice or point me in the direction of a good newbie guide, I'd be much abliged!
Many thanks
Gak