易截截图软件、单文件、免安装、纯绿色、仅160KB

初学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





相关问答:

ruby连接Mysql问题

连接Mysql数据库的时候,老是报这个错误!不知道怎么回事
各位大大们,能否告知,感激不尽

另外,我在公司域中,可能会出现一些问题

NoMethodError in BookController#list
undefined met ......

想找一份Ruby on rails的工作,我应该知道哪些知识?

新年刚开始,已经有一些生猛的朋友要开始新的职场生涯了,
不知道会不会遇到这样的问题: 想找一份Ruby on rails的工作,我应该知道哪些知识 ?
    还好,我并不是想指点你什么,只是想按我的思维方式展 ......

ruby中的or到底是什么意思?

Python code:
puts true or false
puts false or true
为什么上面的输出true,下面的输出false?难道只认or前面的?

据说or后面是直接省略的,不知道是不是这样。
楼上的答案好像不是我想要的

ruby社区怎 ......

初学ruby 怎么把一个类导入呢

1. 例如在
Person.rb 中 
Python code:

class Person
def talk
puts "nihao"
end

end
Student.rb
Python code:

class Student < Person
def talk
puts &quo ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号