易截截图软件、单文件、免安装、纯绿色、仅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 block问题

下面是输出一个小于100的Fibnancci数列:
class test1
  def Fib(max)
    i1,i2 = 1,1
    while i1 <= max
      yield i1
      ......

唐僧!ruby on rails!我欲哭无泪。

本人有点C#跟java底子,回头直接来学ROR。
怎么感觉ROR就那么恶心人,但又很想学好,迫于各方面压力也只能学习ROR。学了大概有两个月吧,可我总感觉自己门都没入……太多的伤心的话就不想多说了,只希望看到的高 ......

ruby 要如何寫bnf

我是用netbeans 去寫bnf

a program will ONLY accept strings based on the following grammar:

            <compute> --> <value> = < ......

Ruby on Rails(急!!!!!!在线等)

HTML code:

<%= link_to_if_authorized l(:field_search_title), {:controller => 'books', :action => 'search', :project_id => @project, :title => @title} %>
<%= text_field_tag 't ......

ruby如何格式化数字?(从右边起每三位一个逗号隔开)

数字从右边起每三位用一个逗号隔开
1232445 ⇒ 1,232,445
---- ChangeStr.rb内容 ------------------------------------------
def change_str(num)
  str = num.to_s
  nil while str. ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号