# \[YANQ\] - how to create/modify \[\]=

**URL:** <https://rubytalk.org/t/yanq-how-to-create-modify/3479>\
**Category:** ruby-talk\
**Created:** [10 December 2002 01:42 UTC](https://rubytalk.org/t/yanq-how-to-create-modify/3479 "2002-12-10T01:42:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_Pena\_Botp1](https://avatars.discourse-cdn.com/v4/letter/_/94ad74/32.png) [@\_Pena\_Botp1](https://rubytalk.org/u/_Pena_Botp1)\
**Post date:** [10 December 2002 01:42 UTC](https://rubytalk.org/t/yanq-how-to-create-modify/3479/1 "2002-12-10T01:42:35Z")

</div>

Hi sir David (aka [dblack@candle.superlink.net](mailto:dblack@candle.superlink.net)):

You enlightened awhile ago:

> You may or may not know it in advance:
> 
> arr[0] =3D gets
> 
> Also, what you’re describing is how assignments work: the return value  
> of the assignment is the right hand side of the expression. True, =3D  
> isn’t an assignment, but a method call… But the cool thing about  
> the =3D syntax is that it looks and acts just like an assignment.
> 
> So, for example, you can do:
> 
> a =3D b =3D arr[0] =3D x
> 
> which would probably blow up if =3D no longer did what it looks like  
> it does (i.e., act like an assignment).

I overlook this. Yes, it does look like an assignment. Thanks, sir David.

> Or, to put it another way: if a method that altered an array element  
> were going to return the array itself, then there would be much better  
> things to call it than =3D .

I’ll take a look at replace or insert. My bad ☹

> If you change Array#=3D globally, then the main repercussions are that  
> you can’t safely use any libraries (including core ones), and no one  
> else can use any libraries or modules you write. So it’s probably not  
> a great idea 🙂 If you do one of the non-global things, like putting  
> the change in a module and extending individual objects, then it’s  
> safer and somewhat more sociable.

My bad. I cannot see big picture… I’ll try creating/extending one… I  
hope it is not difficult…

> David

Many thanks, sir David.  
’ very informative and enlightening.

Kind regards,  
-botp

---

<div class="post-metadata">

**Author:** ![Gavin\_Sinclair](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Gavin\_Sinclair](https://rubytalk.org/u/Gavin_Sinclair)\
**Post date:** [10 December 2002 02:16 UTC](https://rubytalk.org/t/yanq-how-to-create-modify/3479/2 "2002-12-10T02:16:12Z")

</div>

> > If you change Array#=3D globally, then the main repercussions are that  
> > you can’t safely use any libraries (including core ones), and no one  
> > else can use any libraries or modules you write. So it’s probably not  
> > a great idea 🙂 If you do one of the non-global things, like putting  
> > the change in a module and extending individual objects, then it’s  
> > safer and somewhat more sociable.
> 
> My bad. I cannot see big picture… I’ll try creating/extending one… I  
> hope it is not difficult…

Hirofumi’s post already does this - it’s the best solution so far.

Gavin

> **···**
>
> From: “Peña, Botp” [botp@delmonte-phil.com](mailto:botp@delmonte-phil.com)
