cadillac_ has quit [Read error: Connection reset by peer]
ur5us has quit [Ping timeout: 260 seconds]
beefjoe has quit [Ping timeout: 240 seconds]
beefjoe has joined #ruby
cadillac_ has joined #ruby
eckhard__ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
konsolebox has joined #ruby
bak1an has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jamesaxl has quit [Quit: WeeChat 2.1]
ellcs has quit [Ping timeout: 265 seconds]
cagomez has quit [Remote host closed the connection]
zachk has quit [Quit: Leaving]
cagomez has joined #ruby
lxsameer has joined #ruby
kapil___ has quit [Quit: Connection closed for inactivity]
herbmillerjr has joined #ruby
cagomez has quit [Ping timeout: 244 seconds]
mynameisdebian has quit [Remote host closed the connection]
Freshnuts has quit [Quit: Leaving]
alex``` has quit [Ping timeout: 240 seconds]
Freshnuts has joined #ruby
beefjoe has quit [Remote host closed the connection]
lxsameer has quit [Ping timeout: 264 seconds]
darkhanb has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mynameisdebian has joined #ruby
jushY has quit [Remote host closed the connection]
bonhoeffer has joined #ruby
cliq has quit [Ping timeout: 240 seconds]
akaiiro has quit [Ping timeout: 244 seconds]
mynameisdebian has quit [Remote host closed the connection]
Sammichmaker has joined #ruby
bonhoeffer has quit [Quit: bonhoeffer]
lxsameer has joined #ruby
nowhereman_ has quit [Ping timeout: 240 seconds]
nowhereman_ has joined #ruby
lxsameer has quit [Ping timeout: 240 seconds]
lele has quit [Ping timeout: 240 seconds]
lxsameer has joined #ruby
dmgk has joined #ruby
mynameisdebian has joined #ruby
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
jottr has joined #ruby
Tempesta has joined #ruby
lxsameer has quit [Ping timeout: 244 seconds]
graphene has quit [Remote host closed the connection]
SunnyLumenz has joined #ruby
graphene has joined #ruby
cadillac_ has quit [Ping timeout: 244 seconds]
jottr has quit [Ping timeout: 240 seconds]
SunnyLumens has quit [Ping timeout: 264 seconds]
jenrzzz has joined #ruby
jenrzzz has quit [Changing host]
jenrzzz has joined #ruby
mynameisdebian has quit [Remote host closed the connection]
dviola has quit [Quit: WeeChat 2.1]
lele has joined #ruby
jrafanie has joined #ruby
RougeR has quit [Quit: Leaving]
darkhanb has joined #ruby
Emmanuel_Chanel has quit [Read error: No route to host]
tdy has quit [Ping timeout: 244 seconds]
tdy1 has joined #ruby
_Freshnuts_ has joined #ruby
_Freshnuts_ has quit [Remote host closed the connection]
Freshnuts has quit [Quit: Leaving]
kryptoz has joined #ruby
lxsameer has joined #ruby
giz|lazer has joined #ruby
gizmore has quit [Ping timeout: 264 seconds]
jrafanie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
MagePsycho has quit [Ping timeout: 240 seconds]
sameerynho has quit [Ping timeout: 264 seconds]
sylario has quit [Quit: Connection closed for inactivity]
lxsameer has quit [Ping timeout: 264 seconds]
jenrzzz has quit [Read error: Connection reset by peer]
Emmanuel_Chanel has joined #ruby
MagePsycho has joined #ruby
kryptoz has quit [Remote host closed the connection]
pauliesaint has joined #ruby
pauliesaint has quit [Remote host closed the connection]
_whitelogger has joined #ruby
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
pauliesaint has joined #ruby
pauliesaint has quit [Read error: Connection reset by peer]
lxsameer has joined #ruby
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
Emmanuel_Chanel has quit [Ping timeout: 268 seconds]
kapil___ has joined #ruby
lxsameer has quit [Ping timeout: 240 seconds]
lxsameer has joined #ruby
c0ncealed2 has quit [Remote host closed the connection]
c0ncealed2 has joined #ruby
Puffball has joined #ruby
sepp2k has joined #ruby
lxsameer has quit [Ping timeout: 248 seconds]
n13z has quit [Ping timeout: 256 seconds]
\void has joined #ruby
cadillac_ has joined #ruby
<JJonah>
i'm trying to determine an array's levels of nesting. the best i've got so far is: https://eval.in/1036351. is there a terser, preferably more functional, alternative?
braincrash has quit [Quit: bye bye]
AJA4350 has quit [Remote host closed the connection]
TomyLobo has quit [Read error: Connection reset by peer]
graphene has quit [Read error: Connection reset by peer]
graphene has joined #ruby
braincrash has joined #ruby
sepp2k1 has joined #ruby
Emmanuel_Chanel has joined #ruby
Emmanuel_Chanel has quit [Max SendQ exceeded]
sepp2k has quit [Ping timeout: 260 seconds]
Emmanuel_Chanel has joined #ruby
<elomatreb>
JJonah: You could abuse Array#flatten, that gets you a relatively simple solution
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
graphene has quit [Remote host closed the connection]
lxsameer has quit [Ping timeout: 240 seconds]
graphene has joined #ruby
darkhanb has quit [Ping timeout: 264 seconds]
lxsameer has joined #ruby
<evdubs_>
ruby novice here; if you would want to do something in ruby where you read in a .rb file, look at all the functions, and add automatic log statements to the functions showing the local vars, is there a library or something you would look to use?
jenrzzz has quit [Ping timeout: 244 seconds]
<evdubs_>
ideally i could just have a macro that adds the log statements when i want them but i don't think ruby supports macros?
evdubs_ is now known as evdubs
<elomatreb>
evdubs: That gets very difficult. You could instead try a metaprogramming-based solution, e.g. with the method_added hook
djbkd has joined #ruby
n13z has joined #ruby
n13z has quit [Ping timeout: 240 seconds]
jottr has joined #ruby
gix- has joined #ruby
gix has quit [Disconnected by services]
ur5us has joined #ruby
akaiiro has quit [Ping timeout: 244 seconds]
ur5us has quit [Ping timeout: 244 seconds]
lxsameer has quit [Ping timeout: 260 seconds]
lxsameer has joined #ruby
jottr has quit [Ping timeout: 240 seconds]
user3 has quit [Ping timeout: 256 seconds]
donofrio has quit [Remote host closed the connection]
lxsameer has quit [Ping timeout: 264 seconds]
jzhu has joined #ruby
cliluw has quit [Read error: Connection reset by peer]
akaiiro has joined #ruby
akaiiro has quit [Ping timeout: 244 seconds]
podlech has joined #ruby
suukim has joined #ruby
ciscam has quit [Ping timeout: 256 seconds]
ciscam has joined #ruby
lxsameer has joined #ruby
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
alfiemax has quit [Remote host closed the connection]
lxsameer has quit [Ping timeout: 264 seconds]
user3 has joined #ruby
alfiemax has joined #ruby
kedibasi has joined #ruby
akaiiro has joined #ruby
donofrio has joined #ruby
akaiiro has quit [Ping timeout: 260 seconds]
DTZUZO has joined #ruby
lxsameer has joined #ruby
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
kapil___ has quit [Quit: Connection closed for inactivity]
weaksauce has quit [Ping timeout: 240 seconds]
lxsameer has quit [Ping timeout: 240 seconds]
lxsameer has joined #ruby
alex``` has joined #ruby
lxsameer has quit [Ping timeout: 260 seconds]
nowhereman_ has quit [Read error: Connection reset by peer]
nowhere_man has joined #ruby
lxsameer has joined #ruby
karapetyan has joined #ruby
karapetyan has quit [Ping timeout: 240 seconds]
willthechill has quit [Ping timeout: 265 seconds]
lxsameer has quit [Ping timeout: 260 seconds]
user3 has quit [Ping timeout: 265 seconds]
podlech has quit [Quit: WeeChat 2.1]
tag has joined #ruby
ur5us has joined #ruby
Es0teric has joined #ruby
ur5us has quit [Ping timeout: 240 seconds]
willthechill has joined #ruby
kedibasi has quit [Ping timeout: 240 seconds]
jottr has joined #ruby
kedibasi has joined #ruby
jenrzzz has joined #ruby
jenrzzz has joined #ruby
jenrzzz has quit [Changing host]
jottr has quit [Ping timeout: 268 seconds]
mynameisdebian has joined #ruby
Freshnuts has joined #ruby
mynameisdebian has quit [Ping timeout: 276 seconds]
lxsameer has joined #ruby
za1b1tsu_ has joined #ruby
apeiros_ has joined #ruby
lxsameer has quit [Ping timeout: 256 seconds]
lxsameer has joined #ruby
fluxAeon has quit [Ping timeout: 244 seconds]
jzhu has quit [Quit: Connection closed for inactivity]
dellavg has joined #ruby
rippa has joined #ruby
lxsameer has quit [Ping timeout: 244 seconds]
konsolebox has quit [Ping timeout: 260 seconds]
jasmith has quit [Ping timeout: 276 seconds]
jottr has joined #ruby
jasmith has joined #ruby
konsolebox has joined #ruby
lxsameer has joined #ruby
troys has quit [Quit: Bye]
schleppel has joined #ruby
alem0lars has joined #ruby
jottr has quit [Ping timeout: 240 seconds]
lxsameer has quit [Ping timeout: 264 seconds]
alfiemax has quit [Remote host closed the connection]
Mia has quit [Ping timeout: 244 seconds]
kedibasi has quit [Ping timeout: 240 seconds]
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
djbkd has quit []
SeepingN has quit [Quit: The system is going down for reboot NOW!]
jasmith has quit [Quit: Leaving]
naftilos76 has joined #ruby
conta has joined #ruby
jasmith has joined #ruby
lxsameer has joined #ruby
shinnya has quit [Ping timeout: 244 seconds]
sepp2k1 has quit [Read error: Connection reset by peer]
lxsameer has quit [Ping timeout: 260 seconds]
Freshnuts has quit [Quit: Leaving]
karapetyan has joined #ruby
naftilos76 has quit [Quit: Leaving]
za1b1tsu_ has quit [Ping timeout: 260 seconds]
alfiemax has joined #ruby
kedibasi has joined #ruby
Skarlso has joined #ruby
alfiemax has quit [Remote host closed the connection]
alem0lars has quit [Ping timeout: 244 seconds]
Es0teric has quit [Quit: Computer has gone to sleep.]
Kilobyte22 has quit [Quit: ZNC - 1.6.0 - http://znc.in]
Kilo`byte has joined #ruby
lxsameer has joined #ruby
karapetyan has quit [Remote host closed the connection]
kedibasi has left #ruby [#ruby]
karapetyan has joined #ruby
jenrzzz has quit [Ping timeout: 240 seconds]
za1b1tsu_ has joined #ruby
lxsameer has quit [Ping timeout: 260 seconds]
amar has joined #ruby
universal has quit [Read error: Connection reset by peer]
tag has quit [Quit: Connection closed for inactivity]
bonhoeffer has joined #ruby
kliq has joined #ruby
jrafanie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kryptoz has quit [Remote host closed the connection]
mynameisdebian has joined #ruby
lxsameer has joined #ruby
<FernandoBasso>
Inside method defined inside a module, is there a self.<something> that would show the name of the module?
<FernandoBasso>
Like, in a class method, I can do self.class and it shows the name of the class in which the method is defined. Can I show the name of the module in which the module is defined in a similar fashion?
mynameisdebian has quit [Remote host closed the connection]
<apeiros>
self.class.ancestors will contain it
<FernandoBasso>
I see. Thanks.
<apeiros>
but since a method is always invoked in the context of the receiver, there's nothing which will tell you "this is the method defined in module X"
<apeiros>
well, to a degree you can use source_location and/or method(__method__).owner, both have their issues and limitations.
<apeiros>
what do you try to achieve?
<FernandoBasso>
Nothing in particular. Just trying to understand self better, and the relation between modules and classes.
Mike11 has joined #ruby
lxsameer has quit [Ping timeout: 244 seconds]
<apeiros>
self is the object in which's (whose?) context the current code is executed.
Mike11 has quit [Max SendQ exceeded]
lxsameer has joined #ruby
orbyt_ has joined #ruby
<FernandoBasso>
So far, I figure it is, in some ways, similar to `this' in javascript. Its value depending on how the code is executed, and not set in stone upon definition.
<apeiros>
it's exactly as `this` in js. js just differs in when context of `this` changes.
amar has joined #ruby
<FernandoBasso>
I see. All right. Thanks.
lxsameer has quit [Ping timeout: 240 seconds]
lxsameer has joined #ruby
Mike11 has joined #ruby
DTZUZO has quit [Ping timeout: 240 seconds]
bonhoeffer has quit [Quit: bonhoeffer]
kliq has quit [Ping timeout: 244 seconds]
lxsameer has quit [Ping timeout: 240 seconds]
lxsameer has joined #ruby
bak1an has joined #ruby
bonhoeffer has joined #ruby
bonhoeffer has quit [Client Quit]
lxsameer has quit [Ping timeout: 240 seconds]
lxsameer has joined #ruby
alex``` has joined #ruby
<Alec>
apeiros: "for which is the context the code executes in"
GodFather has quit [Remote host closed the connection]
<Alec>
Or "provides the"
<isene>
Using the short form of File.write( file, content ) instead of File.open, is there a way to create the file with permissions 644 at the same time, or do I then have to stick with File.open to achieve that?
<Alec>
isene: you very probably don't want to do that, by opening it first and getting a handler, if the file is moved or deleted the handler follows it and will work (that is it isn't really deleted until all handlers are gone)
dviola has joined #ruby
<Alec>
You can use the creat system call to do this (and usually open with O_CREAT - you can also supply permissions by oring the relevant flags
salasrod has joined #ruby
<Alec>
isene: the importance of "create and open" vs "create then open" is the race condition, if you say run touch or something to make the file, there is a chance that some prick - say me - could delete it and put a link in its place directing you whereever I want you to write - or some shit
<Alec>
For RTFMing you want "man 2 creat"
<Alec>
That's right, they saved one letter.
<lupine>
note that you can also open with a flag that refuses to open a link
<lupine>
which is a nice way to avoid the race
<lupine>
not cross-platform though
<Alec>
That doesn't totally cover you though
<Alec>
But yeah
venmx has quit [Ping timeout: 240 seconds]
<Alec>
isene: a more common mistake is to CHECK IF THE FILE EXITS - and then act, this is also very racy (and a "common" exploit of this class) - you must use creat or open with O_CREAT and set it to fail if it exists.
<isene>
I don't think the race conditions is of any concern here. What I have now is: File.open("npcs/town.npc", File::CREAT|File::EXCL|File::RDWR, 0644) { |fl| fl.write f } But looking to simplify, I would want File.write("npcs/town.npc", f) but with the chmod as 644 (File.write without anything doesn't give 644 rights)
<Alec>
lupine: do you know a lot about POSIX calls or was it like just that bit?
<Alec>
Because I have a problem maybe we could bitch about together or solve
bonhoeffer has joined #ruby
<lupine>
I can try
<lupine>
isene: you also want O_NOFOLLOW
lxsameer has quit [Ping timeout: 264 seconds]
<lupine>
whatever that is in ruby
<Alec>
isene: most file calls are "atomic" - take for example rename, there is never an instance where both the original and target names are valid, for example. So you want to do your opening as ONE call - never two
<Alec>
No he doesn't
<Alec>
lupine: isene you want :
<Alec>
O_CREAT
<Alec>
If the file does not exist it will be created.
<Alec>
from the manual
<Alec>
O_CREAT
<Alec>
If the file does not exist it will be created.
<Alec>
Sorry ctrl+shift+c to copy silly me
<Alec>
O_EXCL Ensure that this call creates the file: if this flag is specified in conjunction with O_CREAT, and pathname already exists, then open() will fail.
<Alec>
Then:
<Alec>
O_EXCL Ensure that this call creates the file: if this flag is specified in conjunction with O_CREAT, and pathname already exists, then open() will fail.
<Alec>
Sorry it wouldn't be more than 6 lines if I hadn't screwed up c&p
<Alec>
When these two flags are specified, symbolic links are not followed: if pathname is a symbolic link, then open() fails regardless of where the symbolic
<Alec>
link points to.
<lupine>
*sob*
<Alec>
lupine: ^
GodFather has joined #ruby
<lupine>
CREAT + EXCL is ok, yeah
<Alec>
There's no point to no-follow
<Alec>
Without EXCL in your scenario
<lupine>
if you're just doing an open() of an existing file you don't want to be a symlink, there is
<Alec>
ALSO I see he already specified it.
<Alec>
Symlinks are good
<lupine>
I jumped in without context, it's a lot of fun :)
<lupine>
sometimes good, sometimes a security risk
<Alec>
You must hate /usr/share :P
<lupine>
it's fine when they're owned by root
<Alec>
Anyway yeah I have an issue with ordered durable writes
<Alec>
How can I do it?
za1b1tsu_ has quit [Ping timeout: 240 seconds]
<lupine>
I don't think you can, really. not reliably
<lupine>
the filesystem or hardware can always override your hints
<Alec>
It is a bitch
<Alec>
"hints"
<Alec>
fsync
<Alec>
But the range fsync rarely can be used
<Alec>
So you have to fsync the directory AND the file
<Alec>
This leads to like 12 fsyncs to do a durable journalled write start to end
GodFather has quit [Remote host closed the connection]
* Alec
is ALWAYS chasing the D - but sometimes he needs to ask "this is good, but at what cost did I achieve this?"
bonhoeffer has quit [Quit: bonhoeffer]
suukim has quit [Quit: Konversation terminated!]
<lupine>
you can open O_DIRECT or O_SYNC of course, but it's still all just hints
<Alec>
VERY difficult to test too.
<lupine>
you can also mmap() the file and use msync()
<lupine>
you *will* need MS_SYNC
fmcgeough has joined #ruby
<Alec>
nah the only way is the two fsycns (which even then may report "it worked" and be lying)
<isene>
So - to my original question - is there a way to simply to File.write to achieve what I want?
<Alec>
Why do you want to?
<Alec>
Just throw in some new lines and say //THESE OPTIONS HAVE TO BE FUCKING SIDE BY SIDE, TOUCH AND I'LL HAVE YOU TOUCHED!
kliq has joined #ruby
<balo>
language pls
TomyLobo has joined #ruby
GodFather has joined #ruby
<Alec>
balo: a compromise happened there, just FYI - "touched" wasn't my first choice.
banisterfiend has joined #ruby
megamosaren has quit [Remote host closed the connection]
c0ncealed2 has quit [Remote host closed the connection]
<Alec>
Hi banisterfiend
c0ncealed2 has joined #ruby
<isene>
I just wondered if there was a way with File.write instead of File.open ... is there?
<Alec>
RTFM m8 - and remember raceconditions are a thing and bad
<Alec>
That's why your OS goes through all the extra work to implement these flags
<isene>
Alec: There is no race condition possible here. Apart from that point, then... is there a way with File.write?
GodFather has quit [Remote host closed the connection]
<Alec>
IF there is no race with your way, then ... well there is no race!
bonhoeffer has joined #ruby
<isene>
Alec: My question was this:
<isene>
What I have now is: File.open("npcs/town.npc", File::CREAT|File::EXCL|File::RDWR, 0644) { |fl| fl.write f } But looking to simplify, I would want File.write("npcs/town.npc", f) but with the chmod as 644 (File.write without anything doesn't give 644 rights)
<Alec>
isene: you can lead a horse to water but you can't make it drink
GodFather has joined #ruby
<isene>
Alec: Do you have an answer to my question?
<Alec>
isene: I'm saying I've taken you to the water and made you aware of the issues, where to find info and check, now you need to do your part.
lxsameer has joined #ruby
<apeiros>
isene: to answer your actual question - yes, File.write accepts a mode parameter which allows you to have it created with the mode you want.
<isene>
Alec: What you did was to raise a point regarding race conditions - which is fine in and of itself - but my question was not about that. And I fail to see that you have led me to any source answering what I actually asked.
<isene>
apeiros: Thank you so much
<apeiros>
ah, no, actually that seems to be to allow you to use w, a or r+
* Alec
poker faces.... "yes, but only if you check the conditions are met"
DLSteve has quit [Quit: All rise, the honorable DLSteve has left the channel.]
hays_ has joined #ruby
<isene>
apeiros: So how would my File.write alternative look like to achieve my current File.open way of doing the file write?
mguex has left #ruby ["WeeChat 2.0"]
hays has quit [Ping timeout: 260 seconds]
GodFather has quit [Remote host closed the connection]
<apeiros>
note mode but perm was the key. sorry for the confusion.
GodFather has joined #ruby
<isene>
apeiros: Thanks a bunch. That was a swift, service-minded fly-by on your part.
apeiros__ has joined #ruby
GodFather has quit [Remote host closed the connection]
bonhoeffer has quit [Read error: Connection reset by peer]
lxsameer has quit [Ping timeout: 264 seconds]
apeiros has quit [Ping timeout: 240 seconds]
GodFather has joined #ruby
bonhoeffer has joined #ruby
bonhoeffer has quit [Client Quit]
apeiros__ is now known as apeiros
jrafanie has joined #ruby
graphene has quit [Read error: Connection reset by peer]
graphene has joined #ruby
clemens3 has quit [Ping timeout: 240 seconds]
GodFather has quit [Remote host closed the connection]
ellcs has joined #ruby
zachk has joined #ruby
zachk has quit [Changing host]
zachk has joined #ruby
Dimik has quit [Ping timeout: 260 seconds]
GodFather has joined #ruby
jrafanie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
quobo has joined #ruby
banisterfiend has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
foobarbaz_ has joined #ruby
foobarbaz_ has quit [Client Quit]
GodFather has quit [Remote host closed the connection]
graphene has quit [Remote host closed the connection]
GodFather has joined #ruby
graphene has joined #ruby
lxsameer has joined #ruby
white_lilies has joined #ruby
<apeiros>
isene: follow up from before, your File::CREAT|File::EXCL|File::RDWR is what would go to the mode kwarg (mode: File::CREAT|File::EXCL|File::RDWR)
lxsameer has quit [Ping timeout: 244 seconds]
clemens3 has joined #ruby
bonhoeffer has joined #ruby
GodFather_ has joined #ruby
GodFather has quit [Ping timeout: 240 seconds]
mynameisdebian has joined #ruby
<isene>
apeiros: Right. Thanks for the follow-up. I have now simplified my code. It's aesthetically cleaner now :-)
lomex has joined #ruby
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
GodFather_ has quit [Remote host closed the connection]
bonhoeffer has quit [Ping timeout: 240 seconds]
amar has quit [Remote host closed the connection]
GodFather has joined #ruby
<apeiros>
yw
GodFather has quit [Remote host closed the connection]
amar has joined #ruby
white_lilies has quit [Ping timeout: 260 seconds]
bonhoeffer has joined #ruby
alfiemax has joined #ruby
clemens3 has quit [Ping timeout: 240 seconds]
GodFather has joined #ruby
akaiiro has joined #ruby
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
lxsameer has joined #ruby
redlegion has quit [Remote host closed the connection]
claudiuinberlin has joined #ruby
redlegion has joined #ruby
ur5us has joined #ruby
nowhere_man has joined #ruby
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
\void has joined #ruby
lxsameer has quit [Ping timeout: 260 seconds]
lxsameer has joined #ruby
blackwind_123 has joined #ruby
mynameisdebian has quit [Remote host closed the connection]
agent_white has quit [Quit: leaving]
mynameisdebian has joined #ruby
Dimik has joined #ruby
lxsameer has quit [Ping timeout: 240 seconds]
clemens3 has joined #ruby
lxsameer has joined #ruby
dellavg has quit [Ping timeout: 276 seconds]
lomex has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
lxsameer has quit [Ping timeout: 240 seconds]
BTRE has quit [Ping timeout: 260 seconds]
lxsameer has joined #ruby
graphene has quit [Remote host closed the connection]
nowhere_man has quit [Ping timeout: 256 seconds]
deadnull has joined #ruby
deadnull has quit [Client Quit]
graphene has joined #ruby
akaiiro has quit [Ping timeout: 260 seconds]
lomex has joined #ruby
<JJonah>
if you define a lambda within a method, as a helper function relevant only to that method, will the interpreter be smart enough to optimize the lambda so that it's only created once and re-used, or will it be created, thrown away, and garbage collected every time the method is invoked?
<Alec>
JJonah: does the lambda have access to any variables that were not passed to it as parameters?
<JJonah>
Alec: no
<Alec>
eg k=5; f = ->(a,b) { return a+b+k; } <---can it get this k?
<Alec>
In that case you will almost certainly get the same lambda each time and let me just test it real quick
<JJonah>
Alec: ah, then maybe. i'd be curious for the answer in both cases, if its different
<Alec>
If it's different JJonah the lambda has to be "bundled" in with the k
<Alec>
You'll get a lambda for each run, carrying its own value of k (well the "type" will carry the data, the lambda code itself will still almost certainly be created once)
<Alec>
Join me in #ruby-community time to work with retard-bot
<JJonah>
Alec: ty, could you also show me how you are testing it? i wasn't sure how to do it myself and would like to know
<Alec>
Join me in #ruby-community time to work with retard-bot
bonhoeffer has quit [Quit: bonhoeffer]
vipaca has joined #ruby
lomex has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
BTRE has joined #ruby
<apeiros>
JJonah: it is likely that e.g. truffleruby will do a better job at optimizing such things. mri tends to be less aggressive in that regard. but there has been a lot of resources spent on improving ruby's performance and thus optimization behavior.
<apeiros>
if it's relevant, just bench it.
BTRE has quit [Client Quit]
d^sh has quit [Ping timeout: 244 seconds]
lxsameer has quit [Ping timeout: 268 seconds]
d^sh has joined #ruby
<JJonah>
apeiros: yeah, i figured this was basic enough that i actually wanted to know how it worked under the hood though.
<apeiros>
while Alec's methodology was flawed over in #ruby-community, we can use the base idea to see that it will at least create a new object every time:
graphene has quit [Remote host closed the connection]
<apeiros>
(that's for MRI, same for 2.5.1, so that part didn't change there)
graphene has joined #ruby
graphene has quit [Remote host closed the connection]
<JJonah>
apeiros: good example, although technically wouldn't that prove only that it recreates it "when it needs to". ie, it might only be recreating it because it's smart enough to know the lambda isn't pure and in this case the "natural" behavior would be broken if it kept it around. but in cases where it there were no ill effects it could...
<JJonah>
related question: ignoring the silliness of this example, i was interested in the scoping rules that prevent the following from working: `def fact(n); step = ->(m) { m == 0 ? 1 : m * step(m - 1) }; step.(n) end`. I mean, lambda's have access to local vars, the step var is in local scope...
amar_ has joined #ruby
<apeiros>
JJonah: you can replace the lambda in the example. I'd expect it to be the same.
<JJonah>
"I'd expect it to be the same." You're right, it is.
white_lilies has quit [Ping timeout: 265 seconds]
<JJonah>
apeiros: doh! ty
<JJonah>
re: dot
<JJonah>
so the bottom line of all this is: if you have a helper function for one of your methods, you're options are 1. create an inner lambda and eat the inefficiency of it being recreated each call 2. make a private helper method relevant and eat the messiness of having a relevant-to-one-method-only helper method on your class 3. make an object to encapsulate the original method and make the helper method private on _that_ object, and
<JJonah>
eat the verbosity
<apeiros>
I think I tend to opt for the private method
<JJonah>
apeiros: agreed, least of all evils
<JJonah>
at least in most cases. if the complexity is high enough 3. becomes worth it.
moei has quit [Quit: Leaving...]
vipaca has quit [Changing host]
vipaca has joined #ruby
<vipaca>
What happened to the Rails channel, why is invite only?
graphene has quit [Remote host closed the connection]
<vipaca>
Did they leave for slack or something?
<samosaphile>
#rubyonrails
graphene has joined #ruby
<vipaca>
Thanks @samosaphile I got it not sure why I didn't see it at first
Caerus has joined #ruby
<headius>
apeiros, JJonah: both JRuby and TR should optimize that case, though TR currently does more to reduce the cost of the closure
karapetyan has joined #ruby
<headius>
the short answer on MRI is that the code block will be reused but the state around it (local variables, self, etc) goes into a memory structure that has to be allocated and then cleaned up later
<headius>
for a simple case JRuby will not allocate as much, and I'm working on getting it to inline and allocate nothing
<JJonah>
headius: thx for the info.
lxsameer has joined #ruby
snickers has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jottr has quit [Ping timeout: 244 seconds]
crankharder has joined #ruby
biberu has quit []
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
fmcgeough has quit [Quit: fmcgeough]
lxsameer has quit [Ping timeout: 260 seconds]
zlogan2003 has joined #ruby
lxsameer has joined #ruby
psychicist__ has quit [Ping timeout: 268 seconds]
lxsameer has quit [Ping timeout: 264 seconds]
schleppel has quit [Quit: Konversation terminated!]
lxsameer has joined #ruby
BTRE has joined #ruby
RougeR has joined #ruby
RougeR has joined #ruby
RougeR has quit [Changing host]
banisterfiend has joined #ruby
SunnyLumens has joined #ruby
vipaca has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
SunnyLumenz has quit [Ping timeout: 264 seconds]
nowhere_man has joined #ruby
shinnya has joined #ruby
ur5us has quit [Remote host closed the connection]
ur5us has joined #ruby
lxsameer has quit [Ping timeout: 260 seconds]
RougeR has quit [Ping timeout: 240 seconds]
lxsameer has joined #ruby
ur5us has quit [Ping timeout: 264 seconds]
tag has joined #ruby
ur5us has joined #ruby
lxsameer has quit [Ping timeout: 240 seconds]
Some-body_ has joined #ruby
DarthGandalf has quit [Ping timeout: 244 seconds]
lxsameer has joined #ruby
ur5us has quit [Ping timeout: 240 seconds]
Some-body_ is now known as DarthGandalf
karapetyan has quit [Remote host closed the connection]
akaiiro has joined #ruby
karapetyan has joined #ruby
RougeR has joined #ruby
RougeR has quit [Changing host]
RougeR has joined #ruby
tty has quit [Quit: tty]
lxsameer has quit [Ping timeout: 240 seconds]
jrafanie has joined #ruby
almdrx has joined #ruby
lxsameer has joined #ruby
jrafanie has quit [Client Quit]
lxsameer has quit [Ping timeout: 244 seconds]
clemens3 has quit [Ping timeout: 240 seconds]
akaiiro has quit [Ping timeout: 268 seconds]
amar_ has quit [Remote host closed the connection]
amar has joined #ruby
amar has quit [Ping timeout: 244 seconds]
salasrod has quit [Remote host closed the connection]
hphat^ has joined #ruby
hphat^ has quit [Max SendQ exceeded]
hphat^ has joined #ruby
hphat^ has quit [Max SendQ exceeded]
hphat^ has joined #ruby
hphat^ has quit [Max SendQ exceeded]
karapetyan has quit [Remote host closed the connection]