I cannot access class

1 view
Skip to first unread message

Rishan Shahrier

unread,
Jun 4, 2008, 6:58:12 AM6/4/08
to code71_on_rubyonrails
My first file:::

Person.rb
class Person
public
def initialize(name)
@name =name
puts @name

end
def index
puts "EHLOO"
end

end

o = Person.new("Rishan")
b = Person.new("anwar")
o.index

this file works fine.
But if i want to access this class from another file then it gives me
following error

uninitialized constant Person (NameError)

Second file P.rb
e=Person.new("Uipoka")

What should i do?

shams zawoad

unread,
Jun 5, 2008, 5:50:22 AM6/5/08
to code71_on_...@googlegroups.com
Rishan,
top of second file put
require '1st_file_name'

This will work.

Thanks,
Ratul

Rishan Shahrier

unread,
Jun 7, 2008, 11:39:25 AM6/7/08
to code71_on_...@googlegroups.com
thanks
it worked :)


--
Take Care
Rishan

Reply all
Reply to author
Forward
0 new messages