初学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
相关问答:
HTML code:
<%= link_to_if_authorized l(:field_search_title), {:controller => 'books', :action => 'search', :project_id => @project, :title => @title} %>
<%= text_field_tag 't ......
Ruby的一个关于求数组的所有子集的程序,
下面的for循环中的对象区间判断,会修改j的值吗?还有j+a..j+b的对象区间是怎么变化的?
我增加打印看值的变化比较奇怪……
class Array
de ......
连接Mysql数据库的时候,老是报这个错误!不知道怎么回事
各位大大们,能否告知,感激不尽
另外,我在公司域中,可能会出现一些问题
NoMethodError in BookController#list
undefined met ......
请问有没有人学习Ruby语言?
这个问题有什么意义?
肯定有
。。。。。。。。。。。。。。呵呵
这个可以有
啪啪地,
。。。有还是没有?
引用
这个问题有什么意义?
散分的意义的有!
哈哈, ......