# How to make a string upcase?

**URL:** <https://www.ruby-forum.com/t/how-to-make-a-string-upcase/147380>\
**Category:** Ruby\
**Created:** [September 1, 2008, 10:12am UTC](https://www.ruby-forum.com/t/how-to-make-a-string-upcase/147380 "2008-09-01T10:12:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [September 1, 2008, 10:12am UTC](https://www.ruby-forum.com/t/how-to-make-a-string-upcase/147380/1 "2008-09-01T10:12:33Z")

</div>

I want to change a string to upcase like below:

name=@value.upcase

But got this error: dynamic constant assignment

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [September 1, 2008, 10:23am UTC](https://www.ruby-forum.com/t/how-to-make-a-string-upcase/147380/2 "2008-09-01T10:23:13Z")

</div>

Hi,

> I want to change a string to upcase like below:
> 
> name=@value.upcase
> 
> But got this error: dynamic constant assignment

Can you post the surrounding code also? Otherwise it will difficult to  
help you.

Pedro

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [September 1, 2008, 10:25am UTC](https://www.ruby-forum.com/t/how-to-make-a-string-upcase/147380/3 "2008-09-01T10:25:07Z")

</div>

On Mon, Sep 1, 2008 at 10:07 AM, Zhao Yi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to change a string to upcase like below:
> 
> name=@value.upcase
> 
> But got this error: dynamic constant assignment

irb(main):001:0\> @value = “test”  
=\> “test”  
irb(main):002:0\> name=@value.upcase  
=\> “TEST”

Can you post more code? The above snippet with a test string for @value  
doesn’t give any error, so it must be something else…

Jesus.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [September 1, 2008, 10:46am UTC](https://www.ruby-forum.com/t/how-to-make-a-string-upcase/147380/4 "2008-09-01T10:46:22Z")

</div>

Zhao Yi wrote:

> I want to change a string to upcase like below:
> 
> name=@value.upcase
> 
> But got this error: dynamic constant assignment

If your variable’s name is uppercase then it’s a constant. This can  
produce the error:

Val=@value.upcase

Don’t start local variable names with uppercase.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [September 1, 2008, 11:05am UTC](https://www.ruby-forum.com/t/how-to-make-a-string-upcase/147380/5 "2008-09-01T11:05:09Z")

</div>

Sebastian H. wrote:

> Zhao Yi wrote:
> 
> > I want to change a string to upcase like below:
> > 
> > name=@value.upcase
> > 
> > But got this error: dynamic constant assignment
> 
> Not for that code you didn’t.  
> If it was Name with a capital N and if the line was inside a method,  
> then  
> you’d get that error. And you’d get that because you’re not supposed to  
> assign constants from within methods (you can get around that, but most  
> of  
> the times, you shouldn’t).
> 
> HTH,  
> Sebastian

oh, it is upcase.

thanks.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [September 1, 2008, 10:54am UTC](https://www.ruby-forum.com/t/how-to-make-a-string-upcase/147380/6 "2008-09-01T10:54:30Z")

</div>

Zhao Yi wrote:

> I want to change a string to upcase like below:
> 
> name=@value.upcase
> 
> But got this error: dynamic constant assignment

Not for that code you didn’t.  
If it was Name with a capital N and if the line was inside a method,  
then  
you’d get that error. And you’d get that because you’re not supposed to  
assign constants from within methods (you can get around that, but most  
of  
the times, you shouldn’t).

HTH,  
Sebastian
