Skip to content

Instantly share code, notes, and snippets.

@blambeau
Created June 20, 2012 16:28
Show Gist options
  • Save blambeau/2960784 to your computer and use it in GitHub Desktop.
Save blambeau/2960784 to your computer and use it in GitHub Desktop.
Path coercible
def source_text(arg)
case arg
when IO then arg.read
when Path then Path(arg).read
else
raise "Unable to find source text for `#{arg}`"
end
end
@eregon
Copy link

eregon commented Jun 20, 2012

What about:

def source_text(arg)
  case arg
  when IO        then arg.read
  when Path.like then Path(arg).read
  else
    raise "Unable to find source text for `#{arg}`"
  end
end

or

def source_text(arg)
  case arg
  when IO         then arg.read
  when Path.like? then Path(arg).read
  else
    raise "Unable to find source text for `#{arg}`"
  end
end

The second is a bit too magic maybe.

@blambeau
Copy link
Author

The first seems more accurate IMHO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment