@nathankerr did a great job translating this, but I do want to mention that as you learn Go more you will want to stop “translating” ruby code and eventually start writing code in a manner more suited to Go. This example is fine, but as a former ruby developer I can definitely tell you that many things you are used to doing in ruby won’t be anything like how I would suggest doing them in Go.
The best way I have found to do this is to stop asking “how do i translate X to Go” and instead asking “What problem does X solve, and how would I solve that problem in Go?”
That said, feel free to post specific ruby examples if you are looking for ideas on what the “go way” is to do something. I found this to be a great way to learning the language as I made the transition.
Also, it’s worth noting that Go OO is based on composition and there’s no class inheritance, so more directly comparable code might be:
module Callable
attr_reader :bar
def initialize(bar)
@bar = bar
end
def call
bar.to_s + ', Hello!!!!'
end
end
class Foo
include Callable
end
my_object = Foo.new("Bob")
puts my_object.call # => "Bob, Hello!!!!"