Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
[ANN] Ducktator - A Duck Type Validator
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Simen Edvardsen, post: 4528036"] The problem with #respond_to? is that it only tells you that a method is supported. It doesn't tell you whether the method takes arguments that quack like the ones you want to pass, or that the return value behaves what you like. In other words, you'll have to trust that the method behaves how you'd like to. Imagine: def make_peace(world) world.create_piece if world.respond_to? :create_piece end class World def make_piece(means = War) means.use! self end end Now make_peace (called with a World) will actually start a war. See the problem? #respond_to? will only tell you that a method is supported, but not that it behaves how you'd like (not that static typing guarantees this either). It saves you from NoMethodError, but not any other error. Duck typing is trusting other objects to do the right thing, and #respond_to? isn't all that useful in that regard. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
[ANN] Ducktator - A Duck Type Validator
Top