At one stage when I was playing around with a few implementations of XML parsing, I had something like
class XmlParserImplementation1 end class XmlParserImplementation2 end XmlParser = XmlParserImplementation1 Andrew On Tue, Mar 10, 2009 at 4:31 PM, Cameron Barrie <[email protected]>wrote: > conditionals on the end of lines. simple but awesome. > puts "Awesome" if @apple.awesome? > > rather than the verbose and less readable C example :P > if (apple->flavour == "awesome") > printf("Awesome\n"); > > You can even use them on the ends of class definitions and such if really > want to. > class Foo > end if defined?(Foo).nil? > > > C > > > > > On 10/03/2009, at 4:15 PM, Daniel N wrote: > > > > On Tue, Mar 10, 2009 at 4:05 PM, Clifford Heath > <[email protected]>wrote: > >> >> On 10/03/2009, at 3:52 PM, Nick Partridge wrote: >> > Symbol-to-proc, and the use of `&` to coerce things to procs: >> > >> > [1,2,3,4,5].select(&:odd?) >> > >> > Awww yeah. >> >> Cute but wasteful, and now deprecated in all Rails core code because of >> the extra (non-gc-able?) object it creates. >> >> I like this for creating and adding to hash values consisting of an >> array: >> >> things_by_key = {} >> things.each do |thing| >> (things_by_key[thing.key] ||= []) << thing >> end >> >> or the same using inject... >> >> Clifford Heath. >> >> > Hey Cliff, > > One of the things I like with hashes is default values set with procs :) > > things_by_key = Hash.new{|h,k| h[k] = []} > things.each do |thing| > things_by_key[thing.key] << thing > end > > I use these all the time for default values in all sorts of ways :) > > Daniel > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en -~----------~----~----~----~------~----~------~--~---
