> ...maybe something like this: > > module Kernel > override print(*args) > do_something > overridden *(args + [" :-)"]) > end > end Yeah the inheritance chain thing is hard. The closest you can come is with modules. class Class def override &block m = Module.new m.module_eval &block include m end end # now class Object override do def print *args super *(args + [" :-)"]) end end end >> print 3 3 :-) ref: http://www.ruby-forum.com/topic/176080#new last post http://yehudakatz.com/2009/03/06/alias_method_chain-in-models/ > But I digress... the purpose of this post is to talk about one of the > relatively > few areas where I think Python beats Ruby, and that's syntatically- > significant > indentation. Not having the "end" is indeed very clean and kind on the eyes--kind of reminds me of what Ruby does, which is try to make things look better for you. The only complaint I've heard about it was from Tony Arcieri's post wondering "how do you return anything from blocks?" i.e. in Ruby "array.collect{|a|}.reject{|b| true}" how to do that with indented blocks. That being said, splitting it up into 3 neat python blocks doesn't look bad at all, so it's not a big loss there. I'm not too familiar with Python syntax so I'm not exactly sure what's possible, either. What would a good syntax be to return values from indented blocks? > My proposal is to, first, not change a thing with respect to existing > syntax. Second, steal the : from Python and use it to signify a scope > that's marked by indentation: I did note Matz recent comment on using the ":" as a separator: http://redmine.ruby-lang.org/issues/show/1389 Perhaps you could take your pitch to him :) > while some_condition: > # this scope will terminate when the indentation level decreases > to the > # level before it was entered > do_something Interesting--so you propose to use : when you want a block but *dont* care about using its return value, is that right? > We can get around this by saying that braces, wherever they may appear, > always define a new scope nested within the current scope, regardless > of indentation. > > def do_something(a, b, c): > { print a, b, c } # this works > a + b + c and then afterward it picks up the previous indentation? I suppose...that would work. It's an odd use for {}'s though which are already pretty heavily used. Overall I like the idea--making "end's" optional would indeed be kind. It is better than a similar idea I had recently, which was to use : for single line blocks (only), i.e. if a == b : do_something instead of if a == b; do_something; end but your suggestion seems to include even more than that. The other concern is that "the allure of magic indentation wears thin for large docs" which fact "worked to ensure you kept your methods short."[1] Also could parsers handle it? Thoughts? =-r [1] http://www.artima.com/forums/flat.jsp?forum=123&thread=256682 -- Posted via http://www.ruby-forum.com/.