<johnjaye>
the description of Object.clone is very confusing to me
<johnjaye>
it's saying if you make a clone of an object with a single instance variable, str, then that variable is cloned but not what it "references"
<johnjaye>
in the example changing str in the clone changes it in the original instance too
constxqt_ has quit [Ping timeout: 246 seconds]
constxqt_ has joined #ruby
<leftylink>
no, that statement is not reflective of what happened in the example.
<leftylink>
in the example, the string pointed to by str was changed. str was not changed.
<johnjaye>
ok. that doesn't make any sense to me.
<johnjaye>
i guess what it's saying is the new object will have a variable. that variable is a string. but it still refers to the original allocated string in memory of the first object
<leftylink>
"that variable is a string" is not possible in Ruby. it is not possible for variables to contain strings. variables may only contain references to strings
<johnjaye>
so the object is a new object but it has the same literal instance variable
<johnjaye>
that's so bizarre. what I would expect is for it to have a new instance variable with possibly the same value as the previous
constxqt_ has quit [Ping timeout: 245 seconds]
<leftylink>
no, I'm not aware of a way for two different objects to have the same instance variable.
<johnjaye>
then why do they have the same object id
<johnjaye>
object id means it's literally the same thing
<leftylink>
c.str and c.clone.str have the same object_id
<leftylink>
instance variables do not have an object id
<johnjaye>
ok. well clearly i'm not grasping something. i will read the docs some more
<filipiz>
this will allow you to list all available versions and do what you are trying to
u0_a1151 has quit [Ping timeout: 255 seconds]
u0_a1151 has joined #ruby
u0_a1151 has quit [Ping timeout: 246 seconds]
constxqt_ has joined #ruby
constxqt_ has quit [Ping timeout: 246 seconds]
lena64t has joined #ruby
pounce has quit [Ping timeout: 244 seconds]
pounce has joined #ruby
taupiqueur_shiny has quit [Remote host closed the connection]
taupiqueur_shiny has joined #ruby
otisolsen70 has joined #ruby
ur5us has quit [Ping timeout: 244 seconds]
u0_a1151 has joined #ruby
constxqt_ has joined #ruby
constxqt_ has quit [Ping timeout: 248 seconds]
tomtmym has joined #ruby
tomtmym has quit [Changing host]
tomtmym has joined #ruby
constxqt_ has joined #ruby
u0_a1151 has quit [Ping timeout: 246 seconds]
u0_a1151 has joined #ruby
szkl has quit [Quit: Connection closed for inactivity]
constxqt_ has quit [Ping timeout: 246 seconds]
u0_a1151 has quit [Ping timeout: 245 seconds]
u0_a1151 has joined #ruby
u0_a1152 has joined #ruby
u0_a1151 has quit [Ping timeout: 246 seconds]
donofrio has quit [Ping timeout: 246 seconds]
<Mindiell>
filipiz: thx, I'll have a look at it
constxqt_ has joined #ruby
constxqt_ has quit [Ping timeout: 246 seconds]
u0_a1153 has joined #ruby
u0_a1152 has quit [Ping timeout: 245 seconds]
sarna has quit [Ping timeout: 245 seconds]
u0_a1154 has joined #ruby
constxqt_ has joined #ruby
u0_a1153 has quit [Ping timeout: 255 seconds]
constxqt_ has quit [Ping timeout: 248 seconds]
konsolebox has joined #ruby
<ox1eef_>
johnjaye: Where as in C you pass by value, in Ruby you pass by reference. When you clone an object, you clone self, but not the instance variables of self (which point to other objects). Those remain referenced to the same object as before. It is not so different to thinking of pointers.
<ox1eef_>
same objects as before*
gr33n7007h has quit [Ping timeout: 250 seconds]
_ht has quit [Quit: _ht]
gr33n7007h has joined #ruby
<aesthetikx>
I have always felt 'pass by reference' and 'pass by value' are pretty lame terms that don't really capture what is happening, ruby and many other langs e.g. java are 'certainly neither' of those
<aesthetikx>
its like asking 'is a snowboard a car or a truck?'
donofrio has joined #ruby
gr33n7007h has quit [Ping timeout: 246 seconds]
gr33n7007h has joined #ruby
u0_a1154 has quit [Ping timeout: 246 seconds]
constxqt_ has joined #ruby
pounce has quit [Ping timeout: 244 seconds]
pounce has joined #ruby
taupiqueur_shiny has quit [Remote host closed the connection]
u0_a115 has joined #ruby
taupiqueur_shiny has joined #ruby
<ox1eef_>
What's your alternative ?
u0_a115 has quit [Ping timeout: 244 seconds]
<ox1eef_>
For me, it makes sense, and that's what important - that it makes sense.
<ox1eef_>
>> def foo(str); str.gsub!("f", "b"); end; x = "foo"; foo(x); x
<ox1eef_>
That's an example of why you say pass by refrence, you mutate an object, and those changes appear in the caller's scope. If you passed by value, then x would never change in the caller's scope.
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
kiwi_36 has joined #ruby
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
taupiqueur_shiny has quit [Remote host closed the connection]
yosef` has joined #ruby
johnjaye has quit [Ping timeout: 260 seconds]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
Ariel68 has joined #ruby
Ariel68 has quit [Client Quit]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
yosef` has quit [Quit: Client closed]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
taupiqueur_shiny has joined #ruby
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
taupiqueur_shiny has quit [Remote host closed the connection]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
blop has quit [Ping timeout: 246 seconds]
blop has joined #ruby
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
blop_ has joined #ruby
infinityfye has joined #ruby
konsolebox has quit [Ping timeout: 245 seconds]
blop has quit [Ping timeout: 246 seconds]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
TomyWork has quit [Remote host closed the connection]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
John_Ivan has joined #ruby
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
leon__ has quit [Ping timeout: 260 seconds]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
taupiqueur_shiny has joined #ruby
eddof13 has joined #ruby
mexen has joined #ruby
lena64t1 has joined #ruby
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
lena64t has quit [Ping timeout: 246 seconds]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
lena64t1 has quit [Ping timeout: 246 seconds]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
Linux_Kerio has quit [Read error: Connection reset by peer]
Linux_Kerio has joined #ruby
u0_a115 has joined #ruby
u0_a115 has quit [Read error: Connection reset by peer]
lena64t has joined #ruby
dviola has quit [Quit: WeeChat 4.0.4]
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
taupiqueur_shiny has quit [Remote host closed the connection]
eddof13 has joined #ruby
eddof13 has quit [Client Quit]
eddof13 has joined #ruby
eddof13 has quit [Client Quit]
eddof13 has joined #ruby
eddof13 has quit [Client Quit]
eddof13 has joined #ruby
Vonter_ has quit [Read error: Connection reset by peer]
dviola has joined #ruby
Vonter has joined #ruby
polishdub has quit [Quit: leaving]
lena64t has quit [Remote host closed the connection]
lena64t has joined #ruby
u0_a115 has joined #ruby
willfish has quit [Ping timeout: 246 seconds]
polishdub has joined #ruby
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
eddof13 has joined #ruby
u0_a115 has quit [Ping timeout: 248 seconds]
u0_a115 has joined #ruby
desnudopenguino1 has joined #ruby
desnudopenguino has quit [Ping timeout: 240 seconds]
desnudopenguino1 is now known as desnudopenguino
Vonter has quit [Ping timeout: 248 seconds]
pounce has quit [Ping timeout: 245 seconds]
Vonter has joined #ruby
pounce has joined #ruby
integral has quit [Server closed connection]
integral has joined #ruby
<leftylink>
I think it's pretty unambiguous and Ruby has only one behaviour
<leftylink>
which is that ruby passes references by value
mexen has quit []
<leftylink>
there is no case when Ruby passes by reference
<leftylink>
the language simply does not support it
<leftylink>
however, if the objection is that these two terms are not useful (whether it's because the discussed languages do not meaningfully differ on this dimension OR it's because the terms are too easily misunderstood), then sure, I will not object to that objection
<leftylink>
nor will I object to the proposal of new useful terms. I'm simply saying which of these existing terms applies, which is not to be taken as an endorsement of the terms
donofrio has quit [Ping timeout: 246 seconds]
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
donofrio has joined #ruby
<weaksauc_>
ruby does pass by reference though.
dza has joined #ruby
u0_a115 has quit [Ping timeout: 246 seconds]
Linux_Kerio has quit [Ping timeout: 250 seconds]
<leftylink>
pandabot rb def foo(a); a = :changed end; a = :unchanged; foo(a); a
<leftylink>
as we see from the above code, s was changed, so Ruby passes references, through which you can mutate. Whether Ruby passes references or not is unrelated to whether Ruby passes by reference
<leftylink>
in fact, what can Ruby possibly pass, except references? references are pretty much all we have, since one of the ideals espoused by Ruby is that everything is an object
taupiqueur_shiny has joined #ruby
tomtmym has quit [Quit: Gone.]
blop has joined #ruby
ur5us has joined #ruby
blop_ has quit [Ping timeout: 246 seconds]
<ox1eef_>
The reference point is C (which johnjaye knows), and in K&R C "pass by value" is defined as a function receiving a *copy* of its argument, so if Ruby were pass by value, mutation would not work because it would have a copy of an object.
<ox1eef_>
Either way, it's most useful when you know C, and in those terms, makes perfect sense.
<weaksauc_>
well yeah in c everything is pass by value
<weaksauc_>
where you can simulate reference passing by dealing with pointers
<ox1eef_>
Kind of, when you pass a pointer, you have a reference to the caller's scope, and that's how you can achieve the same thing as Ruby - more or less.
<leftylink>
I guess I just see it differently. I think it's important to be clear about the difference between an object and a reference to that object
<ox1eef_>
void foo(int *x) { (*x)++; } void main(void) { int x = 1; foo(&x); }; - should print 2.
<ox1eef_>
Sure, everyone has a different conceptual model, but for johnjaye, as a C programmer, I think it is more relatable.
<weaksauc_>
i mean & and * are just syntactic sugar for memory location and value of that memory location... it's all still passing in by value in c as x inside foo is the memory location and if you modified that it would have no change to the memory location of x in the outside scope. almost essentially the sam e as what you did in the string or symbol swapping thing
<ox1eef_>
Dunno. It makes sense to me, and clearly it is subjective, but that's one way to explain it in relatable terms.
<leftylink>
well, the most important thing will be to have a clear picture of what is and isn't possible, regardless of what the names are
<weaksauc_>
value to me is immutable things. a 1 is a 1. it's a value.
<ox1eef_>
Agree x2.
<constxqt_>
imo ruby passes arguments by value
<ox1eef_>
Not by the K&R C definition.
<constxqt_>
a why?
<constxqt_>
s/^a //
<leftylink>
because the thing that's passed is a reference, and you get a copy of the reference, by the K&R C definition, it's pass by value.
<constxqt_>
^
<ox1eef_>
Because it defines pass by value as receiving a *copy*, and if you had a copy of an object, then mutations wouldn't be seen by the caller.
<constxqt_>
consider this ruby code: a = []; b = a
<constxqt_>
is b a reference to a? no, they're *both* references to an array
<constxqt_>
passing arguments works just like assignment
<ox1eef_>
You said ruby is pass by value, but your last statement contradicts that entirely.
<constxqt_>
no because assignment also creates copies
<weaksauc_>
a and b both reference the same object_id
<weaksauc_>
which is a reference to the same memory location and the same object
<ox1eef_>
Okay, and how do you call something pass by value, but then describe it entirely as references ?
<weaksauc_>
i don't
<ox1eef_>
To constxqt_
<constxqt_>
def f(x) x = 40 end k = 4; f(k); # why isn't k == 40?
<leftylink>
whether we pass objects or references is unrelated to whether arguments are passed by value or by reference
<ox1eef_>
You can't mutate numbers in Ruby. They're a special case.
<ox1eef_>
And, their object_id is the same.
<ox1eef_>
Same object.
<weaksauc_>
they are values
<weaksauc_>
yes
<leftylink>
in Ruby, references are passed by value. there may well be some language that passes objects by value, passes objects by reference, or passes references by reference, but we are talking about Ruby here
<constxqt_>
replace numbers with literally anything and that example still works
<leftylink>
which passes references by value
<weaksauc_>
constxqt_ sure because scope
<constxqt_>
assigning to a parameter can't change the argument
<constxqt_>
because arguments are passed by value
<ox1eef_>
Because Ruby doesn't have pointers, but again, it depends how you define "pass by value". By the K&R C definition, it's not pass by value, because that would imply having a new object I think I agree with leftylink's last message the most.
<constxqt_>
if the argument is itself a reference to an object, then the parameter can be used to mutate the underlying object, because it is a copy of that exact reference
<weaksauc_>
it is a reference to an object not a label
<weaksauc_>
reassigning the label just changes the label
<ox1eef_>
So if I understood you correctly, you think Ruby is the same as C, but everything is a pointer.
taupiqueur_shiny has quit [Remote host closed the connection]
taupiqueur_shiny has joined #ruby
<ox1eef_>
I don't disagree with that either.
u0_a115 has joined #ruby
<adam12>
I rewatched a talk I linked here yesterday/day before (wycats) and noticed that Ruby Conf 12 had a crazy awesome lineup
taupiqueur_shiny has quit [Remote host closed the connection]
Demi has quit [Server closed connection]
taupiqueur_shiny has joined #ruby
Demi has joined #ruby
<ox1eef_>
Yeah, Ruby had a bright future once upon a time.
<ox1eef_>
Sky was the limit.
<ox1eef_>
But I kinda think its popularity was its worst enemy in the end.
taupiqueur_shiny has quit [Remote host closed the connection]
otisolsen70 has quit [Quit: Leaving]
infinityfye has quit [Quit: Leaving]
jess is now known as JESS
JESS is now known as jess
leftylink has quit [Server closed connection]
leftylink has joined #ruby
ur5us has quit [Ping timeout: 250 seconds]
z4kz has quit [Server closed connection]
z4kz has joined #ruby
ur5us has joined #ruby
mretka has quit [Server closed connection]
mretka has joined #ruby
marahin has quit [Server closed connection]
marahin has joined #ruby
entropie has quit [Ping timeout: 245 seconds]
Arthur has quit [Server closed connection]
Arthur has joined #ruby
ruby[bot] has joined #ruby
entropie has joined #ruby
lena64t has quit [Ping timeout: 246 seconds]
<constxqt_>
ox1eef_: why dont u still think it has a bright future
<constxqt_>
seems like ruby is in a good place ruby 3 seems pretty solid
entropie has quit [Ping timeout: 244 seconds]
entropie has joined #ruby
johnjaye has joined #ruby
ur5us has quit [Quit: Leaving]
eddof13 has joined #ruby
conjunctive has quit [Server closed connection]
conjunctive has joined #ruby
u0_a115 has quit [Ping timeout: 246 seconds]
<ox1eef_>
Well, it was a time when Ruby had the limelight, the job market was bustling, and the ecosystem had solutions that were considered ahead of other languages, but I don't think much if any of that is true anymore. Kind of stagnated, and a lot of people moved on. But I don't think it is a dead language or anything like that.
kiwi_36 has quit [Remote host closed the connection]
teclator has quit [Ping timeout: 248 seconds]
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]