trillp has quit [Remote host closed the connection]
michigan has joined #ruby
Rounin has quit [Ping timeout: 256 seconds]
factor1 has joined #ruby
factor has quit [Ping timeout: 260 seconds]
factor1 is now known as factor
mahlon has quit [Ping timeout: 268 seconds]
lad has joined #ruby
mahlon has joined #ruby
michigan has quit [Quit: Connection closed for inactivity]
pgib has joined #ruby
ur5us has quit [Ping timeout: 264 seconds]
lad has quit [Remote host closed the connection]
fusta has quit [Quit: Leaving]
jpw has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 264 seconds]
vit has joined #ruby
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 256 seconds]
gr33n7007h has joined #ruby
gr33n7007h has quit [Read error: Connection reset by peer]
gr33n7007h has joined #ruby
jpw has quit [Remote host closed the connection]
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 264 seconds]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
Rounin has joined #ruby
duds- has quit [Ping timeout: 276 seconds]
gr33n7007h has quit [Quit: WeeChat 3.3]
shokohsc8 has quit [Read error: Connection reset by peer]
shokohsc8 has joined #ruby
reset has quit [Quit: reset]
gr33n7007h has joined #ruby
kenichi has quit [Ping timeout: 260 seconds]
kenichi has joined #ruby
Busk has joined #ruby
trillp has joined #ruby
tempate has joined #ruby
duds- has joined #ruby
<tempate>
I have an sorted array of numbers. Is there an elegant way to get all the elements below a certain value (which is not be in the array)?
Busk has quit [Quit: My computer has gone to sleep. ZZZzzz…]
gr33n7007h has quit [Ping timeout: 256 seconds]
gr33n7007h has joined #ruby
tempate has quit [Quit: Leaving.]
gr33n7007h has quit [Client Quit]
jetchisel has quit [Ping timeout: 268 seconds]
jetchisel has joined #ruby
duds- has quit [Ping timeout: 276 seconds]
Guest89 has joined #ruby
Guest89 has quit [Client Quit]
duds- has joined #ruby
duds- has quit [Ping timeout: 276 seconds]
leonthemisfit has quit [Ping timeout: 268 seconds]
tempate has joined #ruby
tempate has quit [Client Quit]
lunarkitty has quit [Quit: Connection closed for inactivity]
<adam12>
tempate is gone, but I wonder if #partition would work.
<jhass[m]>
I think partition iterates the entire array, so it's slightly less performant than bsearch_index + #[] in this case
<adam12>
jhass[m]: I totally forgot about bsearch.
<jhass[m]>
aww, you shouldn't, it's amazing for the few cases where it's useful :D
<adam12>
Ruby is so damn awesome
<adam12>
I wonder when the 3.1 preview is going to drop.
walidvb has joined #ruby
bastelfreak has quit [Quit: WeeChat 3.3]
<walidvb>
hey all, just asked this on rubyonrails, but realize it's more of a ruby issue..
<walidvb>
i created a class method that define_methods. That class method takes in a block. When that block is run, it seems to be run on the class, rather than the instance. Any clue? code => https://gist.github.com/walidvb/b02c7485bb2c9e578157ba5e55bd2c6f
<jhass[m]>
Yes, unless you change it with instance_eval, blocks are called with their definition scope
<jhass[m]>
in this simple example you could also simply forward the block to define_method, which also changes its execution scope
<walidvb>
jhass[m] will look those up, thanks:)
<walidvb>
which is cleaner, in your opinion?
<walidvb>
ah, you mean therefore move the block down to the instance code
<jhass[m]>
Personally I'm not a big fan of passing arguments through setting instance variables
<jhass[m]>
especially in a metaprogramming context like this it can quickly become confusing IMO
bastelfreak has joined #ruby
<walidvb>
i hear you. i need this to be generic, though.
<jhass[m]>
but if you really just want your proc to be come a method body as is, just forwarding it as define_method's block argument certainly is the most succint
<walidvb>
would you have a `*args` ?
<jhass[m]>
probably, it's hard to judge without the full context :)
<walidvb>
well, various mailers have a way to select templates, based on their variables(which i could of course pass to the `template_name` method)
<jhass[m]>
doing define_method(:something, &some_lambda) should make the defined method gain the lambda's signature fwiw
<walidvb>
some based on `@export`, others on `@user`, etc
<walidvb>
aah ok think i got it
<walidvb>
although this means i then need to pass the block to the call to `template_name`, no?
<walidvb>
(i sorta liked the cleanliness of having the whole thing on one line, all contained within the `add_templates` call at the top of the class)
<jhass[m]>
no, I don't follow why you'd need to pass any block at the call of the defined method
<walidvb>
i'm not sure how you'd define it, then 🤔
Inline has joined #ruby
<jhass[m]>
in your example you could do define_method(:template_name, &block) instead of what you're currently doing
<walidvb>
if i `define_method(:foo, &bar)`, then i'd need to call `foo { my_block}`
<walidvb>
ok lemme check
<walidvb>
wait, is my last statement incorrect?
CrazyEddy has quit [Ping timeout: 260 seconds]
<jhass[m]>
I think so
<jhass[m]>
then if you make the lambda -> (export) { export.type } you'd need to call it with template_name(@export)
<walidvb>
yeah i guess that's what i was trying to avoid.
<walidvb>
hoping to make my main functions agnostic of how template_name is run (although you'll argue that they require instance vars to be set (@export in this case))
<jhass[m]>
Yes, it's just an implicit dependency
Inline has quit [Quit: Leaving]
<walidvb>
ended up going with `define_method(:foo, &block)`, but i'm not sure i understand how that became an instance call 🤔
<jhass[m]>
it's just intrinsic behavior of how define_method treats its block argument
<walidvb>
(and tbh the whole thing should work differently, to start with. atm i need the functions to be defined as this is how i grab the templates available to show to the user – wrong 😅)
<walidvb>
> it's just intrinsic behavior of how define_method treats its block argument
<walidvb>
i'll have to take your word for it, and find time to read some more
<walidvb>
thanks for your help!
Inline has joined #ruby
<jhass[m]>
> This block is evaluated using instance_eval.