cappy has quit [Remote host closed the connection]
mange has joined #ruby
dvinciguerra has joined #ruby
dvinciguerra has quit [Read error: Connection reset by peer]
dvinciguerra has joined #ruby
dvinciguerra has quit [Remote host closed the connection]
eddof13 has joined #ruby
sola has joined #ruby
<sola>
I'm trying to override the [] and []= methods for a file class to be able to read customizable amounts of items much like a standard array slice (a[5, 2] = [6,7]). This works well enough when all arguments are provided, but when I do simply a[5] for example, then the item after the = sign will now be interpreted as the one that should be inside the brackets. How do I fix this?
<sola>
for example if it were "def []=(i, length = 1, content = nil)" then when I type "a[5] = 7", 7 will become the "length" and content is now nil
eddof13 has quit [Quit: eddof13]
<sola>
ah, never mind, I honestly thought I already tried making only the middle parameter have a default value and it gave me an error, but I guess that was just trying to make only the middle one a keyword parameter
brokkoli_origin has quit [Ping timeout: 245 seconds]
brokkoli_origin has joined #ruby
<havenwood>
sola: You might even consider a `case args` with `in [index, length, value]` then `@data[index, length] = value`, and an `in [index, value]` as the alternative.
snoojin has quit [Quit: Connection closed for inactivity]
cappy has joined #ruby
quorra has quit [Quit: Updating details, brb]
quorra has joined #ruby
cappy has quit [Quit: Leaving]
cappy has joined #ruby
cappy has quit [Quit: Leaving]
user71 has joined #ruby
<leftylink>
hey so I know that in the past, Ruby used to have String#each . and they removed it because it's not clear what the unit of iteration should be, fine
<leftylink>
is ARGF#each at risk in the same way?
<leftylink>
it currently iterates over lines
<leftylink>
should I trust that it will remain that way, or is there a risk that it will be removed?
<leftylink>
so if there are any plans to remove it, they are secret, unknown, or not yet been put forward
grenierm has joined #ruby
Linux_Kerio has joined #ruby
<havenwood>
leftylink: Consider Ruby 1.8 a different language. Matz has been hesitant to break anything since 1.9. That said, something could always get deprecated and removed in a decade. I'd not worry.
hwpplayer1 has joined #ruby
user71 has quit [Quit: Leaving]
grenierm has quit [Ping timeout: 256 seconds]
hwpplayer1 has quit [Remote host closed the connection]
Linux_Kerio has quit [Quit: Konversation terminated!]
Linux_Kerio has joined #ruby
grenierm has joined #ruby
nirvdrum has quit [Quit: Ping timeout (120 seconds)]
JulioPapel has joined #ruby
nirvdrum has joined #ruby
grenierm has quit [Ping timeout: 256 seconds]
grenierm has joined #ruby
cappy has joined #ruby
grenierm has quit [Ping timeout: 256 seconds]
donofrio has joined #ruby
JulioPapel has quit [Quit: JulioPapel]
donofrio has quit [Ping timeout: 252 seconds]
cappy has quit [Read error: Connection reset by peer]
cappy has joined #ruby
cappy has quit [Quit: Leaving]
cappy has joined #ruby
donofrio has joined #ruby
rvalue has quit [Read error: Connection reset by peer]
rvalue has joined #ruby
<leftylink>
I don't come across or want to do this often, I guess, but I guess every time I do it surprises me that it's not allowed.
<leftylink>
pandabot: rb 0 + p 1
<pandabot>
stderr: -e:2: syntax error, unexpected integer literal, expecting `do' or '{' or '(' - exit 1 - https://carc.in/#/r/hh0j
<v0n>
If there something similar to Enumerable to deal with file-like objects, which have a content that you can set, append, etc.?
<v0n>
s/If/Is/
Starfoxxes has joined #ruby
JulioPapel has joined #ruby
JulioPapel has quit [Quit: JulioPapel]
eddof13 has joined #ruby
Perflosopher has quit [Quit: Ping timeout (120 seconds)]
Perflosopher has joined #ruby
<havenwood>
v0n: Have an example of one thing you might do?
<havenwood>
You can do getters and setters on any Object, so I'm not quite following the ask.
donofrio has quit [Read error: Connection reset by peer]
donofrio_ has joined #ruby
JulioPapel has joined #ruby
Sampersand has joined #ruby
donofrio_ has quit [Remote host closed the connection]
donofrio_ has joined #ruby
JulioPapel has quit [Quit: JulioPapel]
ule has quit [Quit: WeeChat 3.8]
dviola has quit [Quit: WeeChat 4.4.3]
rvalue- has joined #ruby
rvalue has quit [Ping timeout: 246 seconds]
rvalue- is now known as rvalue
donofrio_ has quit [Ping timeout: 248 seconds]
Sampersand has quit [Quit: Client closed]
donofrio_ has joined #ruby
cappy has joined #ruby
<havenwood>
Mmm, maybe you mean like a mixin that automatically uses Delegate to some store like a Hash? I'm just not sure quite what it'd look like, but with an example we can probably point you in the direction.
user71 has quit [Quit: Leaving]
donofrio_ has quit [Ping timeout: 260 seconds]
eddof13 has quit [Quit: eddof13]
ollysmith has quit [Quit: ZNC 1.9.1+deb2+b1 - https://znc.in]
ollysmith_ has joined #ruby
mms has joined #ruby
eddof13 has joined #ruby
cappy has quit [Quit: Leaving]
mretka has joined #ruby
mretka has quit [Changing host]
polishdub has quit [Read error: Connection reset by peer]
polishdub has joined #ruby
eddof13 has quit [Quit: eddof13]
hwpplayer1 has joined #ruby
hwpplayer1 has quit [Remote host closed the connection]
gr33n7007h has quit [Quit: WeeChat 4.4.4]
polishdub has quit [Ping timeout: 260 seconds]
gr33n7007h has joined #ruby
polishdub has joined #ruby
phenom_ has quit [Ping timeout: 260 seconds]
phenom has joined #ruby
zph1nx has quit [Remote host closed the connection]
zphinx has joined #ruby
eddof13 has joined #ruby
eddof13 has quit [Client Quit]
meimei has joined #ruby
pounce has joined #ruby
smp has quit [Ping timeout: 255 seconds]
smp has joined #ruby
<johnjaye>
In ruby you can redefine any method at any time right?
<johnjaye>
Is this what's called "monkey patching"?
smp has quit [Ping timeout: 260 seconds]
<weaksauce>
johnjaye yes
smp has joined #ruby
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
<johnjaye>
ok. is there a linting or warning mechanism to mention if this happens to a base class?
<johnjaye>
or do people sometimes have a reason to redefine Array or String
<weaksauce>
redefine?
<weaksauce>
some people do monkeypatch core classes but it is considered a little bit of a smell
<havenwood>
johnjaye: No, no warnings or anything. Folk use mixins or refinements to do it nicely.
<havenwood>
johnjaye: Interface is the only reason to redefine Array or String, but usually if you really, really want to you don't mind if it's lexically scoped so refinements work.
<havenwood>
Most folk just don't in practice.
<havenwood>
Then again, even stdlib takes liberties.
<havenwood>
It's a Ruby thing. Just reopen a core class and have fun.
<johnjaye>
haha ok
<havenwood>
Even in unexpected ways. Like `require 'optparse'` defines a method on ARGV.
<havenwood>
And that's not uncommon, for better or worse.
<havenwood>
"Monkeypatching, you'll shoot you're eye out" is mostly untrue _only_ because irresponsible folk like Rails and stdlib are the only ones who have the gall.
<havenwood>
It's only a problem in case of conflict.
<havenwood>
If there's only one offender, there's no conflict.
<havenwood>
Just make sure you're the worst actor.
<havenwood>
Not ideal, but mostly works, like Ruby namespaces.
<havenwood>
They cause tens of thousands of hours of bugs and related coding but do "work fine" in the end.
<havenwood>
Maybe in Ruby 4 we'll get proper namespaces?
<havenwood>
I don't mind waiting if they're done well. On the other hand, we're late to the game.