I just started learning Ruby and I need to create a template where it replace my strings with hashes that I write. What I need to add in my code?
This is my code, I write two methods for my task, help please with your suggestions
def initialize(template_string, local_variables)
@template_string = template_string
@local_variables = local_variables
end
def compile()
@template_string.gsub()
end
end
puts Template.new("I like %{x}", x:"coffee").compile # x = coffee
puts Template.new("x = %{x}", y:5).compile # unknown x
puts Template.new("x = %{x}", x:5, y:3).compile # x = 5, ignores y
Aucun commentaire:
Enregistrer un commentaire