Created
October 12, 2013 19:14
-
-
Save pootsbook/6953750 to your computer and use it in GitHub Desktop.
URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Url | |
attr_reader :url | |
def initialize(url) | |
raise(ArgumentError, "url not specified") unless url | |
@url = url | |
end | |
def to_uri | |
URI.parse(url) | |
end | |
end | |
url = Url.new(ARGV[0]) # will raise an ArgumentError if ARGV[0] is nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes:
attr_reader
instead of the instance variable. Rationale: depend on behaviour not data (POODR)$errors
. If you give me a bit of background I can have a think about what might work better.