Hi,
Can someone explain the role of the “?” before the “x”
s = “abcdefg”
s[0] = ?x # s == “xbcdef”
I know this will accomplish the same thing.
s[0] = ‘x’
Thanks,
Buzz
Hi,
Can someone explain the role of the “?” before the “x”
s = “abcdefg”
s[0] = ?x # s == “xbcdef”
I know this will accomplish the same thing.
s[0] = ‘x’
Thanks,
Buzz
On Sun, Nov 23, 2008 at 12:35 AM, Buzz H. [email protected]
wrote:
s[0] = ‘x’
sigma ~ % irb
s = “abcdefg”
s[0] = ?x
?x
s
s[0] = ‘x’
s
‘x’[0]
s[0]
s[0,1]
‘x’[0,1]
^ manveru
On Sat, Nov 22, 2008 at 9:35 AM, Buzz H. [email protected] wrote:
s[0] = ‘x’
irb(main):004:0> ?a
=> 97
It’s an integer value keyword.
Programming Ruby: The Pragmatic Programmer's Guide has more
information under “Integer and Floating Point Numbers”
irb(main):005:0> x = " "
=> " "
irb(main):006:0> x[0] = ?a
=> 97
irb(main):007:0> x
=> “a”
End result for the string you modify is the same because String#[]=
with a single integer index accepts either integers or strings.
irb(main):002:0> x[0] = ‘abc’
=> “abc”
irb(main):003:0> x
=> “abc”
-Michael L.
Michael F.
Michael L.
It’s an integer value keyword.
End result for the string you modify is the same because String#[]=
with a single integer index accepts either integers or strings.
Thanks. I am new and not familiar with all the symbol meanings.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs