tags:

views:

52

answers:

2

In Python

>>> import string
>>> string.uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

or

>>> string.digits
'0123456789'

Is there a way to use a string constant in Ruby?

+3  A: 

I'm not aware of any string constants like that in Ruby, but you could specify a range of characters to achieve the same thing:

>> ('A'..'Z').to_a.join("")
=> "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>> ('0'..'9').to_a.join("")
=> "0123456789"
Pär Wieslander
+1  A: 

There are nothing like that in ruby. But it's easy to do this

class String

  def self.uppercase
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  end

  def self.digits
    '0123456789'
  end
end

After you can call it

String.uppercase
String.digits
shingara