Re: define and call methods in ruby



Jay Pangmi wrote:
maybe I'm wrong. but what I'm saying is (Here's what I do in java)

public class myclass
{
.....
String name;
static int i=0;
//defining a instance method
public void setName(String name)
{
this.name=name;
}
//defining the method.
public void printMessage()
{
System.out.println("Message");
}
//for some event
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==xxxx)
{
printMessage(); //declaring a method in the same class.
}
}
........
}

public class anotherclass extends myclass
{
myclass mc;
int j;
..............
mc.setName("James"); //calls method with the instance of the class
j=myclass.i; //here coz i belongs to class.
}

Hope, it clears out what I'm trying to do. Just example, not very good in java either...
So, what I'm trying to do is declare similar method as printMessage() in ruby. thanks

A mantra for you.. Ruby is not Java repeat 100 times until you believe it. Then start learning Ruby all over again with a beginner's mind. Java is compiled, Ruby interpreted. Ruby knows nothing of your display method until it sees it.. see my previous post.
R

--
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321
.



Relevant Pages

  • Re: Calling a class from a button
    ... public void Button1_Click ... myClass c = new myClass ... >> How do I call a public class function in C# from a button ... > public class TextFromFile ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to use generics?
    ... getting rid of the ACollection and BCollection and just having Collectionwould be a good start towards using generics to the full extent. ... public void AddCollection() ... public bool ContainsKey ...
    (microsoft.public.dotnet.languages.csharp)
  • program challenge
    ... public void setName{ ... the salaried class that extends Employee ... public class Salaried extends Employee ... // Programmer.java: the programmer class that extends from Hourly ...
    (comp.lang.java.help)
  • Re: Tricky form problem
    ... > ShowDialog method) different modal child forms. ... when using ShowDialog() there's no ... > public class MainForm: Form ... > public void ShowForm() ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Accessing at runtime nested methods parameters values
    ... private object val; ... public override string ToString() ... public class Call ... public void PushName ...
    (microsoft.public.dotnet.languages.csharp)