开发者

Ruby class inheritance of included gems

class Foo
  require 'somegem'
end

class Bar < Foo
 def to_开发者_JS百科s
  puts Somegem.somemethod
 end
end

Why is this not working/how can I get something like this to work?


$ cat somegem.rb

class Somegem
  def self.somemethod
    "somemethod"
  end
end

$ cat foo.rb

class Foo
  require 'somegem'
end

class Bar < Foo
 def to_s
  puts Somegem.somemethod
 end
end

bar = Bar.new()
bar.to_s

$ ruby foo.rb
somemethod

But I'm not exactly sure though, what you tried to accomplish ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜