Ruby on Rails Tuesday, December 27, 2011

On Tue, Dec 27, 2011 at 7:04 AM, sachin kewale <sachinkewale@gmail.com> wrote:
hi all,

  i am getting the following warning for "numeric_slug = /^[0-9]+$/" this line in my model class,
  "warning: character class has `-' without escape"

Strange ... I copy/pasted your piece of code, and works fine here.
The '-' acts as a range (from '0' to '9').

peterv@ASUS:~/b$ rvm use 1.8.7
Using /home/peterv/.rvm/gems/ruby-1.8.7-p352
peterv@ASUS:~/b$ irb
001:0> numeric_slug = /^[0-9]+$/
=> /^[0-9]+$/
002:0> numeric_slug.match("1234")
=> #<MatchData "1234">
003:0> numeric_slug.match("1234aa")
=> nil
 
 
  can anyone know the what is the escape character used in regex ?
  i am using Ruby:1.8.7,gem:1.6.2,Rails:2.3.11.

The escape character is a backslash. So, if you really wanted to match a '-'
you could do 2 things:
* escape the '-' as '\-'
* place the '-' the last entry in the character class

 peterv@ASUS:~/b$ rvm use 1.8.7 # also tested in 1.9.3
Using /home/peterv/.rvm/gems/ruby-1.8.7-p352
peterv@ASUS:~/b$ irb
001:0> numeric_and_dash = /^[\-0-9]+$/
=> /^[\-0-9]+$/
002:0> numeric_and_dash.match("01234-5678-91")
=> #<MatchData "01234-5678-91">
003:0> numeric_and_dash.match("0+4")
=> nil
004:0> numeric_and_dash = /^[0-9-]+$/
=> /^[0-9-]+$/
005:0> numeric_and_dash.match("01234-5678-91")
=> #<MatchData "01234-5678-91">


  Also, i want to up grade my current version of Ruby ,Rails and gem with latest one ,but i don't  know what are compatible and stable latest version for ruby and rails with  
  rubygem ?

I currently use the combination below from up-to-date rvm. For development,
best is to set-up rvm , if you did not already have it.

Current up-to-date setting with rvm is:

rvm : version 1.10.0           # rvm get latest
ruby : 1.9.3[-p0]                  # rvm list known | egrep '\[ruby\-\].*\[' | tail -1
rails : 3.1.3   (close to 3.2) # gem list -r rails | grep 'rails '
rubygems : 1.8.10              # rvm rubygems current

HTH,

Peter

--
Peter Vandenabeele
http://twitter.com/peter_v

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment