[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: using classes problem

Gavin Kistner

10/16/2006 4:41:00 PM

From: Scott D_o
> I am trying to use a class that I wrote in another file, and
> it doesn't
> seem to want to work. At the beginning of the file that I do [require
> 'classname'] with the single quotes

a) What is the name of the file that you put your class in?
b) Where is the file, relative to the file that has the "require" line
in it?

16 Answers

Scott d_o

10/17/2006 2:24:00 AM

0

Gavin Kistner wrote:
> From: Scott D_o
>> I am trying to use a class that I wrote in another file, and
>> it doesn't
>> seem to want to work. At the beginning of the file that I do [require
>> 'classname'] with the single quotes
>
> a) What is the name of the file that you put your class in?
> b) Where is the file, relative to the file that has the "require" line
> in it?

Ok so here is some code that is having the problem with the require. I
tested out some programs from rubyforge, and it gave me the same error.
-----------------------------------------------------------------
TestClass two seperate files
-----------------------------------------------------------------
class TestClass
def testMethod()
return "Hello I am in TestClass"
end
end

-----------------------------------------------------------------
ClassTester
-----------------------------------------------------------------
require 'TestClass'

ob = TestClass.new()
puts("Testing: #{ob.testMethod()}")
-----------------------------------------------------------------

Thanks

--
Posted via http://www.ruby-....

Scott d_o

10/17/2006 3:38:00 AM

0

Satish Talim wrote:
> Ok so here is some code that is having the problem with the require. I
> tested out some programs from rubyforge, and it gave me the same error.
> ------------------------------
>> -----------------------------------------------------------------
>> ClassTester
>> -----------------------------------------------------------------
>> require 'TestClass'
>>
>> ob = TestClass.new()
>> puts("Testing: #{ob.testMethod()}")
>> -----------------------------------------------------------------
>>
>
> It works for me. Both the program files are in the same folder.
>
> Here's a slightly modified code (normally the () is not there after the
> method name. We use lowercase characters for method names and _
> character to
> separate out the multi-words in a method name. I am also using
> single-quotes
> for plain strings (the first case in your program).
>
> # testclass.rb
> class TestClass
> def test_method
> 'Hello I am in TestClass'
> end
> end
>
> # classtester.rb
> require 'testclass'
> ob = TestClass.new
> puts("Testing: #{ob.test_method()}")
>
> The output -
>>ruby classtester.rb
> Testing: Hello I am in TestClass
>>Exit code: 0
>
> Hope this helps.

Nope it still gives me the same error. IDK what to do, cause I tried it
on two computers and they both give me the same one. On both computers I
installed ruby using the 1click installer, do you think this would have
any effect on it, or are there certain config files that I can check to
make sure everything is in order?
Thanks

--
Posted via http://www.ruby-....

Gavin Kistner

10/17/2006 3:45:00 AM

0

Scott D_o wrote:
> Gavin Kistner wrote:
> > a) What is the name of the file that you put your class in?
> > b) Where is the file, relative to the file that has the "require" line
> > in it?
>
> Ok so here is some code that is having the problem with the require. I
> tested out some programs from rubyforge, and it gave me the same error.
> -----------------------------------------------------------------
> TestClass two seperate files
> -----------------------------------------------------------------
> class TestClass
> def testMethod()
> return "Hello I am in TestClass"
> end
> end
>
> -----------------------------------------------------------------
> ClassTester
> -----------------------------------------------------------------
> require 'TestClass'
>
> ob = TestClass.new()
> puts("Testing: #{ob.testMethod()}")

You didn't answer either of my questions.

What is the name of the FILE that you have your TestClass defined in?
It should be something like "testclass.rb". That's what you should put
in your require statement, e.g.
require 'testclass.rb'

Also, unless you're installing it somewhere in your require path, you
should have that file in the same directory as your 'class tester' file.

Scott d_o

10/17/2006 4:17:00 AM

0

Satish Talim wrote:
> On 10/17/06, Scott D_o <s.pullen05@gmail.com> wrote:
>> >> puts("Testing: #{ob.testMethod()}")
>>
> One more thing - under what name have you stored your require TestClass
> program?

I have it named as TestClass.rb if that is what you are asking

--
Posted via http://www.ruby-....

J2M

10/17/2006 2:00:00 PM

0

Scott,

A couple of things, probably not the cause, but you seem to have some
of the naming conventions mixed...

assuming that both files are in the same directory, it is good practice
to not use cases in your file names, so I would code them;

-----------------------------------------------------------------
testclass.rb
-----------------------------------------------------------------
class TestClass
def testMethod()
return "Hello I am in TestClass"
end
end

-----------------------------------------------------------------
classtester.rb
-----------------------------------------------------------------
require 'testclass'

ob = TestClass.new()
puts("Testing: #{ob.testMethod()}")
-----------------------------------------------------------------

The require is the filename without the .rb extension.


Scott d_o

10/18/2006

0

James Mccarthy wrote:
> Scott,
>
> A couple of things, probably not the cause, but you seem to have some
> of the naming conventions mixed...
>
> assuming that both files are in the same directory, it is good practice
> to not use cases in your file names, so I would code them;
>
> -----------------------------------------------------------------
> testclass.rb
> -----------------------------------------------------------------
> class TestClass
> def testMethod()
> return "Hello I am in TestClass"
> end
> end
>
> -----------------------------------------------------------------
> classtester.rb
> -----------------------------------------------------------------
> require 'testclass'
>
> ob = TestClass.new()
> puts("Testing: #{ob.testMethod()}")
> -----------------------------------------------------------------
>
> The require is the filename without the .rb extension.

No I used require 'testclass', and I tried running it in freeIDE, and
for some reason it actually ran, so I don't know what the deal is when I
try to run it from console, it just gives me that rubygem custom require
error.

--
Posted via http://www.ruby-....

J2M

10/19/2006 6:48:00 AM

0

so you are doing that from rails console rather than irb?


El Castor

9/14/2012 7:09:00 AM

0

On Fri, 14 Sep 2012 00:30:20 -0500, wiljan@nospam.pobox.com (Will
Janoschka) wrote:

>On Fri, 14 Sep 2012 04:18:37, mg <mgkelson@yaoo.com> wrote:
>
>> On Thu, 13 Sep 2012 18:25:50 -0400, Jim_Higgins
>> <gordian238@hotmail.com> wrote:
>>
>> >Should Profiling be used for National Security?
>> >http://tinyurl.c...
>>
>> I, personally, have no objection to profiling non U.S. citizens.
>> Profiling American citizens, though, is something different.
>>
>> I wouldn't mind, for instance, a sign in an airport that said "All
>> foreign Muslims must go through this line". I would object to a sign,
>> though, that said, "All Muslims must go through this line".
>>
>I agree. That is perhaps too fine a distinction for religious bigots.

How about a sign that read, "All Muslims get in line to receive your
hood and handcuffs and be flown back to whence you came -- never to
return. Prayers, chants, and references to Allah not permitted while
in the air. You might scare the paying passengers." Would that be ok?

>Our government need make the distinction between "all",
>and "we the people of". Security for "government" or 'those
>that rule, according to the constitution". The US government
>is the highest threat to "we the people". I do not, in any way
>agree with the concept of the TSA.
>
>There are very few that board an airplane, that want to do
>anything except, get off the damned thing on the other end.
>
>Preventing large aircraft from flying into buildings with 500
>tons of fuel is a whole different thing. That is an engineering
>problem, not a law problem. Never been addressed!

Gary

9/14/2012 11:02:00 AM

0

On Thu, 13 Sep 2012 22:18:37 -0600, mg <mgkelson@yaoo.com> wrote:

>On Thu, 13 Sep 2012 18:25:50 -0400, Jim_Higgins
><gordian238@hotmail.com> wrote:
>
>>Should Profiling be used for National Security?
>>http://tinyurl.c...
>
>I, personally, have no objection to profiling non U.S. citizens.
>Profiling American citizens, though, is something different.
>
>I wouldn't mind, for instance, a sign in an airport that said "All
>foreign Muslims must go through this line". I would object to a sign,
>though, that said, "All Muslims must go through this line".

All Muslims are foreign to American culture, traditions and ideals.
I have no problem with an Arab coming to this country -- IF. If he
throws of his sheet and sandals, shaves his beard and strives to
become an American.

Alias

9/14/2012 11:11:00 AM

0

On 9/14/2012 1:02 PM, Gary wrote:
> If he
> throws of his sheet and sandals, shaves his beard and strives to
> become an American.

So, you would have Lincoln, Grant and all the other bearded Americans
that they should shave? How about Jesus and his sandals and beard?

--
Alias