addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [ruby-81] a few simple ruby (non-rails) questions

From: Travis H.
Sent on: Wednesday, July 28, 2010 5:03 PM
On Wed, Jul 28, 2010 at 07:47:43PM -0400, Travis H. wrote:
> What do you folks think about that?

This actually works, and retains backwards compatibility with my older
new.create_from_file­(...) syntax:

  def initialize(method=ni­l, *args)
    case method
      when :file then create_from_file(*ar­gs)
      when :parts then create_from_parts(*a­rgs)
      when :string then create_from_string(*­args) # unused
      # if no method, do no intialization

IMHO, I like that a lot better than the canonical answer (branching
based on argument types).  I can add or remove args, change types, add
default arguments, etc., and never have to alter the initialize

> What I'm wanting to do is ignore entirely and simply
> have three class methods that construct and initialize objects.

It also takes less code than defining class methods for each possible
way to create a class.  In that case I have to define three methods,
and use some fugly syntax for class methods (I like "def self.method"
much better than "def ClassName.method" since it's easier to rename
classes - following the "don't repeat yourself" guideline).

Anyway, yay for scripting languages, argument lists, and symbols.
I knew there had to be a decent way to do this.

Okay, I'll stop spamming y'all now... ;-)
A Weapon of Mass Construction
My emails do not have attachments; it's a digital signature that your mail
program doesn't understand. | http://www.subspa...­ 
If you are a spammer, please email [address removed] to get blacklisted.

This email message originally included an attachment.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy