T
Trans
I have a choice to make about a class interface. This is a very very
simplified "foo" demo of that choice.
#1
class Foo
def initialize(bar)
@bar = bar
end
def okay?
bar.okay?
end
end
bar = Bar.new
Foo.new(bar)
Or #2
class Foo
def initialize( opts )
@okay = opts[kay]
end
def okay?
@okay
end
end
bar = Bar.new
Foo.newokay => bar.okay?)
Now, my inner OOP Angel is telling me to take door #2 in order to
avoid strong coupling between Bar and Foo. But, my Red Ruby Devil is
saying "Duck typing, you fool. It doesn't matter anymore!"
Is he right? Has Ruby completely changed the game? If so, why aren't
more Rubyists using OStruct-esque option passing?
T.
simplified "foo" demo of that choice.
#1
class Foo
def initialize(bar)
@bar = bar
end
def okay?
bar.okay?
end
end
bar = Bar.new
Foo.new(bar)
Or #2
class Foo
def initialize( opts )
@okay = opts[kay]
end
def okay?
@okay
end
end
bar = Bar.new
Foo.newokay => bar.okay?)
Now, my inner OOP Angel is telling me to take door #2 in order to
avoid strong coupling between Bar and Foo. But, my Red Ruby Devil is
saying "Duck typing, you fool. It doesn't matter anymore!"
Is he right? Has Ruby completely changed the game? If so, why aren't
more Rubyists using OStruct-esque option passing?
T.