From: Shashank Date Date: 2002-10-22T20:16:42+09:00 Subject: Re: newby asks: giving regexps as argument for funvtions This worked for me under ruby 1.7.2 (2002-07-02) [i386-mswin32]: def findPosRE(str, re) m = re.match(str) return m.begin(0) end pos = findPosRE("hey you behind the wall", /behind/) puts pos # prints 8 "T-Online" wrote in message news:ap3a59$dm4$06$1@news.t-online.com... > Hi this is a newby question: > > i want to pass a regular expression as a parameter to ruby. Tthe following > code snippet can be made easier but it shows the principle I want to > understand: > > def findPosRE(str, re) > m = %r{re}.match(str) > return m.begin(0) > end > > > pos = findPosRE ("hey you behind the wall", "/behind/") > > > This gives the error: > > -->undefined method 'begin' for nil (NameError) > > How I convince ruby that the local variable m is a MatchData object, so the > begin() method can be sent to m ? > > Ciao, > > Daniel. > >