user94154
user94154

Reputation: 16574

Ruby class inheritance of included gems

class Foo
  require 'somegem'
end

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

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

Upvotes: 1

Views: 309

Answers (1)

miku
miku

Reputation: 188114

$ 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 ...

Upvotes: 1

Related Questions