From: Matthew Kerwin Date: 2012-09-22T11:49:20+09:00 Subject: Re: How would you allow variable from specific list of Fixnum? On 22 September 2012 05:05, Brandon Weaver wrote: > On Sep 21, 2012, at 1:48 PM, Eliezer Croitoru wrote: > >> On 9/21/2012 6:18 PM, 7stud -- wrote: >>> Jan E. wrote in post #1076932: >>>> Hi, >>>> >>>> Why is everybody using this Java-like exception syntax nowadays? Is >>>> there some book teaching this? >>>> >>>> Use >>>> >>>> raise SyntaxError, "Modes Allowed: #{modes}" >>>> >>> >>> Because that syntax is dumb? >>> >> If there is not difference in the operation such as in: >> newregex = /[\d]+/ >> newregex = Regexp.new("[\\d]+") >> >> so there is not really a good reason to use one or the other since the result is the same. >> >> Thanks, >> Eliezer >> >> -- >> Eliezer Croitoru >> https://www1.ngtech.co.il >> IT consulting for Nonprofit organizations >> eliezer ngtech.co.il >> > > It's a matter of efficiency and clarity. Besides, regex is actually: > > Test =~ /t/ > > http://www.ruby-doc.org/core-1.9.3/Regexp.html > > Lo and behold, the docs have imparted divine wisdom on such subjects of implementation. > > Brandon Weaver #=~ is the test-using-this-regex operator, #= is the assignment operator. Eliezer was, I think, completely right in saying that `newregex = /[\d]+/` and `newregex = Regexp.new("[\\d]+")` are equivalent, but one the is "better" (cheaper, faster, cleaner, whatever) than the other. This is analogous to the choice between using `raise SyntaxError, "foo bar"` and `raise SyntaxError.new "foo bar"`. -- Matthew Kerwin, B.Sc (CompSci) (Hons) http://matthew.kerwin.net.au/ ABN: 59-013-727-651 "You'll never find a programming language that frees you from the burden of clarifying your ideas." - xkcd