RubyConference quiz
Build a library that adds a class method called build()
to Regexp
. This method should accept a variable number of arguments, which can include Integers and Ranges of Integers. Have build()
return a Regexp
object that will match only Integers in the set of passed arguments.
Here are some examples of possible usage:
lucky = Regexp.build(3, 7)
"7" =~ lucky # => truthy
"13" =~ lucky # => falsey
"3" =~ lucky # => truthy
month = Regexp.build(1..12)
"0" =~ month # => falsey
"1" =~ month # => truthy
"12" =~ month # => truthy
day = Regexp.build(1..31)
"6" =~ day # => truthy
"16" =~ day # => truthy
"Tues" =~ day # => falsey
year = Regexp.build(98, 99, 2000..2005)
"04" =~ year # => falsey
"2004" =~ year # => truthy
"99" =~ year # => truthy
num = Regexp.build(0..1_000_000)
"-1" =~ num # => falsey
- Obviously you should use
ruby
for solving this. - Extra point for solutions completely following ruby-style-guide
- You will receive additional points for covering different edge cases.
- On March 20, 2015 we will send free RubyConference tickets to 3 winners.
- Fork this repository
- Add a folder with same name as your account on github.
- Write your solution inside your folder.
- Send us a pull request.
Once your pull request is merged - you are accepted.
MAY THE FORCE BE WITH YOU!