Requesting a high-level overview of how to structure the directory of a project using the Template Design Pattern in Ruby.
I have a project
directory with one venue.rb
file & one folder containing base.rb
. I see them used a lot in my companies Ruby on Rails project but would like to understand how to structure the project regarding the template design pattern independent of Rails.
Current Setup:
~./project
+--venue.rb
+--venue
| |
+--base.rb
venue.rb
require_relative 'venue/base'
class Venue
end
puts "Loaded class Venue:"
a = Venue.new
a.base
~./project/atm/base.rb
module Base
class Venue
def base
puts "base"
end
end
end
puts "Loaded module Base:"
When I run the venue.rb
I get:
#=> ruby venue.rb
Loaded module Base:
Loaded class Venue:
venue.rb:9:in `<main>': undefined method `base' for #<Venue:0x007fe77209cf20>
(NoMethodError)
I'm pretty sure I've misunderstood inheritance but I believe this should work. Any suggestions would be appreciated. Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire