初学ruby 怎么把一个类导入呢
1. 例如在
Person.rb 中
Python code:
class Person
def talk
puts "nihao"
end
end
Student.rb
Python code:
class Student < Person
def talk
puts "nihao"
end
end
p = Student.new
p.talk
结果
>ruby Student.rb
Student.rb:1: uninitialized constant Person (NameError)
>Exit code: 1
经典 酷! book_simmone
自己添加require上去就行了~~~不过发现csdn ruby on rails 貌似人不多阿~~
不用那么麻烦的,在ruby中,include就可以实现继承
Python code:
class Student
include Person
def talk
puts "nihao"
end
end
相关问答:
做了三年。NET了
当然。NET水平也很烂
想多学一些新的语言
这两天在学习RUBY
不知道将来有没有前途
RUBY前辈们,指点一二啊。
别这山看着那山高,其实它们只是你的一个工具,就象武林高手拿个树叶 ......
我是用netbeans 去寫bnf
a program will ONLY accept strings based on the following grammar:
<compute> --> <value> = < ......
连接Mysql数据库的时候,老是报这个错误!不知道怎么回事
各位大大们,能否告知,感激不尽
另外,我在公司域中,可能会出现一些问题
NoMethodError in BookController#list
undefined met ......
1. 例如在
Person.rb 中
Python code:
class Person
def talk
puts "nihao"
end
end
Student.rb
Python code:
class Student < Person
def talk
puts &quo ......