Gears Within Gears

Seek simplicity, and distrust it.

Chicago: in fashion

Posted by Brian Guthrie Sat, 14 Apr 2007 06:04:00 GMT

I’m in Chicago tonight for another job interview tomorrow. Never been to Chicago before, so that’s very cool, and I’m excited about the interview. Not much more to say except that downtown Chicago is stunning (and I get a 28th-floor view here), and that overriding Proc#call does not in fact affect the behavior of yield. Nobody expects the Spanish inquisition:

class Proc
  def weird(*args)
    # Only get all weird if we ask for it.
    puts "weird call!" if args.length > 0 && args[0] == "weird"
    orig_call(*args)
  end
  alias :orig_call :call
  alias :call :weird
end

def weird_call(str, &block)
  block.call(str)
end

def weird_yield(str)
  yield(str)
end

and you get:

>> weird_call("weird") { true }
weird call!
=> true
>> weird_yield("weird") { true }
=> true

This is frustrating, because I wanted Handshake to be able to support:

  contract Block(String => Integer) => 1..5

For example. Am I wrong? Or is there another mechanism for overriding the behavior of yield?

The degree to which Ruby’s core methods don’t appear to be orthogonal, instead employing lower-level mechanisms to do their work (Class#=== vs. Object#is_a? is another example) has been an unpleasant surprise to me.

1 comment | Tags , , , | atom

Trackbacks

Use the following link to trackback from your own site:
http://blog.brianguthrie.com/trackbacks?article_id=chicago-in-fashion&day=14&month=04&year=2007

Comments

Leave a response

  1. Aaron 2 days later:

    I’m going to be honest. Despite having this explained to me on more than one occasion, I still can’t say I really understand it.

    How are Ruby’s core methods not oriented at 90 degrees to one another? If you meant “orthogonal” in the sense that they’re well-separated, maybe that isn’t the best word choice.

    You could, instead, use some of those fluffy CS terms, saying that Ruby’s methods are too coupled.

Leave a comment