<Vashy>
hm looks like I had to install `rspec` separately, when I ran `gem install rspec` it worked
<Vashy>
I assumed `rspec-rails` was enough because of their documentation
nicholaslyang has quit [Client Quit]
<apotheon>
You said you ran `bundle install` -- right? I'd expect that to install rspec, unless for some reason rspec isn't a dependency of rspec-rails.
<apotheon>
. . . which would be weird, I think.
<apotheon>
I'm glad you got it working.
<apotheon>
Oh . . . I wonder if you had something in your Gemfile.lock that conflicted with what you needed.
<apotheon>
Maybe?
<apotheon>
oh well
<apotheon>
I'm off for dinner. Ta.
TCZ has quit [Quit: Leaving]
AndreYuhai has quit [Quit: Leaving]
nicholaslyang has joined #ruby
nicholaslyang has quit [Client Quit]
justache has joined #ruby
nicholaslyang has joined #ruby
quazimodo has joined #ruby
oddp has quit [Ping timeout: 264 seconds]
jayx has joined #ruby
tau has quit [Ping timeout: 264 seconds]
ur5us has quit [Ping timeout: 260 seconds]
nofxx has quit [Remote host closed the connection]
* Roelof
hopes he has not missed the answer to his last question
<leftylink>
well, it is important to know that the channel logs are linked in the channel topic.
rubydoc has quit [Ping timeout: 265 seconds]
phaul has quit [Ping timeout: 264 seconds]
isxek is now known as rcl
rcl is now known as d00fuz
phaul has joined #ruby
<Roelof>
leftylink thanks
<Roelof>
according to the log I miss the answer
<leftylink>
so now you know
<Roelof>
pity that on the I do not how many minutes the connection get lost
rubydoc has joined #ruby
d00fuz is now known as rcl
rcl is now known as d00fuz
d00fuz is now known as rcl
rcl has quit [Quit: Leaving]
d00fuz has joined #ruby
donofrio has joined #ruby
alfiemax has quit [Remote host closed the connection]
alfiemax has joined #ruby
alfiemax has quit [Ping timeout: 246 seconds]
rubydoc has quit [Ping timeout: 260 seconds]
phaul has quit [Ping timeout: 260 seconds]
* Roelof
hopes he can now stay long in this channel
<sarna>
roelof: there's a service called irccloud that could in theory make your connection more stable
<sarna>
I think they include two hours of logs in their free plan
<sarna>
if you pay, you get unlimited history I think
<jhass>
or if you have a spare box just install ZNC :P
<sarna>
and a spare few hours ;)
<jhass>
most of that time is not installing ZNC but configuring a decent IRC client :P
rubydoc has joined #ruby
phaul has joined #ruby
roelof_ has joined #ruby
<sarna>
well, or configuring ZNC itself
<sarna>
it's a whole experience
<jhass>
I feel like you getty pretty far with the defaults at first
<sarna>
yeah true
_Caerus has quit [Ping timeout: 260 seconds]
dionysus69 has joined #ruby
alfiemax has joined #ruby
<Roelof>
hmm, is there a better way to solve this one :
<Roelof>
```
<Roelof>
class ResistorColorDuo COLORS = %w(black brown red orange yellow green blue violet grey white) def self.value(string) outcome = 0 for i in 0 .. 1 outcome = outcome * 10 + COLORS[string[i]] end outcome end
d00fuz has quit [Remote host closed the connection]
TCZ has joined #ruby
<Roelof>
hmm, maybe I can better use map
<Roelof>
I will experimnt more
Caerus has joined #ruby
<sarna>
roelof: I think `(0..1).each do |i| ... end` would be more idiomatic
rubydoc has quit [Ping timeout: 240 seconds]
phaul has quit [Ping timeout: 246 seconds]
<Roelof>
sarna I did solve it this way : ` string[0..1].map { | item| COLORS.index(item) }.join.to_i `
<sarna>
roelof: looks nice!
<Roelof>
thanks, and for a beginner :)
<sarna>
I'm a beginner as well :)
ineb has joined #ruby
<leftylink>
it makes you wish the join didn't have to happen, because it is a shame to have to convert it to a string only to convert it back to an integer, but since the problem only says to deal with two colours, my concern about using join is misplaced here
<Roelof>
oke, if there is a way without the join im happy to learn
<ineb>
What is a good way to wrap json responses from a web API in a ruby object? Lets say the API returns {"foo": "bar"}, i want a 'robust' ruby object like response.foo # => "bar". I think i want these objects dynamically. I have looked at OpenStructs and Hashie but they do not look 'robust' because in case of response.not_existing, they always return 'nil' instead of method_missing
GodFather_ has quit [Ping timeout: 256 seconds]
<Roelof>
leftylink is there then a method I can add all the indexes up and multiply the old one with 10 ?
<jhass>
roelof: you only need to handle two values. How about using a + ?
<jhass>
and a * to put one of the digits into its right decimal place
phaul has joined #ruby
<ineb>
jhass: ty, i will look at it.
<Roelof>
@jhass you mean something like `COLORS.index(string[0]) * 10 + COLORS.index(string[1[) `
rubydoc has joined #ruby
<jhass>
yeah
<Roelof>
oke, thanks
stryek has joined #ruby
phaul has quit [Ping timeout: 265 seconds]
rubydoc has quit [Ping timeout: 240 seconds]
phaul has joined #ruby
rubydoc has joined #ruby
rubydoc has quit [Remote host closed the connection]
rubydoc has joined #ruby
<Roelof>
I like this one too : ` string[0..1].reduce(0) { |total, item| total * 10 + COLORS.index(item) } `
<Roelof>
that can be expanded to more if needed
phaul has quit [Ping timeout: 256 seconds]
rubydoc has quit [Ping timeout: 260 seconds]
<jhass>
one the one hand yes, otoh it makes an uncessary two element array
<jhass>
actually isn't it wrong?
<jhass>
ah, now I see, it does 0 * 10 on the first iteration
<Roelof>
All the tests are green so it suppose/assumed that the code is allright ?
jetchisel has quit [Quit: Unfortunately time is always against us -- [Morpheus]]
<jhass>
yeah
<jhass>
idk it feels too smart for this simple problem :)
memcorrupt has quit [Ping timeout: 265 seconds]
memcorrupt has joined #ruby
memcorrupt has quit [Changing host]
memcorrupt has joined #ruby
Technodrome has joined #ruby
burningserenity has joined #ruby
burningserenity has quit [Client Quit]
burningserenity has joined #ruby
phaul has joined #ruby
rubydoc has joined #ruby
darkstardev13 has quit [Remote host closed the connection]
darkstardev13 has joined #ruby
con3 has quit [Ping timeout: 258 seconds]
rubydoc_ has joined #ruby
rubydoc has quit [Excess Flood]
phaul has quit [Ping timeout: 265 seconds]
rubydoc_ has quit [Ping timeout: 265 seconds]
drincruz has quit [Ping timeout: 264 seconds]
freshmaker666 has quit [Quit: ZNC 1.7.2 - https://znc.in]
<sarna>
I reverted to webmock alone, I can't get VCR to work with any of the HTTP libraries :( I don't know if it's a bug in VCR or something else
drincruz has joined #ruby
<sarna>
anyway - can you specify that a request with some parameters have been made on a stub?
<sarna>
oh there's a with in the stub :facepalm:
BrianWGray has quit [Ping timeout: 264 seconds]
<sarna>
..but HTTP doesn't put params in the URL, oh lord
<sarna>
oh it does! I had a bug :)
<adam12>
ineb: You could try creating a new Object then using define_singleton_method for each field, and return the value. This may have unintended performance implications with the GC and method cache.
<ineb>
adam12: yeah, i think another simple solution is to just wrap the actual hash and check for key existence before accessing anything
<adam12>
ineb: Yep. That would work fine too if you're not opposed to method_missing.
phaul has joined #ruby
rubydoc_ has joined #ruby
sarna has quit [Quit: Connection closed]
wymillerlinux has joined #ruby
phaul has quit [Ping timeout: 240 seconds]
rubydoc_ has quit [Ping timeout: 256 seconds]
phaul has joined #ruby
rubydoc_ has joined #ruby
TCZ has quit [Ping timeout: 240 seconds]
BrianWGray has joined #ruby
cd has quit [Ping timeout: 260 seconds]
alfiemax has quit [Remote host closed the connection]
alfiemax has joined #ruby
Roelof has quit [Ping timeout: 245 seconds]
roelof_ is now known as roelof
akem has joined #ruby
reffle has joined #ruby
alfiemax has quit [Ping timeout: 260 seconds]
memcorrupt has quit [Ping timeout: 258 seconds]
MrCrackPot has joined #ruby
memcorrupt has joined #ruby
memcorrupt has quit [Changing host]
memcorrupt has joined #ruby
d00fuz has joined #ruby
ChmEarl has joined #ruby
burningserenity has quit [Ping timeout: 240 seconds]
dionysus69 has quit [Ping timeout: 264 seconds]
arahael1 has joined #ruby
snuz has quit [Read error: Connection reset by peer]
darkstardev13 has quit [Remote host closed the connection]
shokohsc has joined #ruby
<roelof100>
and now I have to wait till a mentor approves it. Have the max challenges done where I can ask for mentor approval
fercell has quit [Quit: WeeChat 2.8]
<phaul>
&renick
rubydoc_ is now known as rubydoc
<rubydoc>
okay
Bounga has joined #ruby
ellcs1 has quit [Ping timeout: 260 seconds]
Bounga has quit [Remote host closed the connection]
Bounga has joined #ruby
renich_ has joined #ruby
Bounga has quit [Remote host closed the connection]
renich has quit [Ping timeout: 240 seconds]
renich_ is now known as renich
renich has quit [Client Quit]
Bounga has joined #ruby
Bounga has quit [Remote host closed the connection]
<roelof100>
wish you all a good evening its supper time for me :
Bounga has joined #ruby
drincruz has quit [Ping timeout: 240 seconds]
donofrio_ has joined #ruby
<sagax>
hi all!
<sagax>
if i need recursion but i have error about this - what i can do?
donofrio_ has quit [Remote host closed the connection]
donofrio_ has joined #ruby
donofrio has quit [Ping timeout: 264 seconds]
nychtel has joined #ruby
nychtel has quit [Client Quit]
alfiemax has quit [Remote host closed the connection]
burningserenity has joined #ruby
stdedos has joined #ruby
<adam12>
sagax: What's the error? are you referring to tail recursion?
roelof100 has quit [Ping timeout: 245 seconds]
TomyWork has quit [Remote host closed the connection]
drincruz has joined #ruby
howdoi has joined #ruby
Eiam has joined #ruby
<havenwood>
sagax: Show us!
dionysus69 has quit [Remote host closed the connection]
orbyt_ has joined #ruby
FastJack has quit [Ping timeout: 258 seconds]
FastJack has joined #ruby
stdedos has quit [Quit: Connection closed]
<sagax>
>> stack level too deep
<ruby[bot]>
sagax: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
ellcs1 has joined #ruby
<adam12>
sagax: We'd need the full stack trace pasted somewhere. Ruby doesn't (IIRC) have natural tail recursion without a flag, which isn't enabled by default.
<Uncle_Cid>
Dude in discord has "def level_order(node = @root)" as method signature, and I can't quite figure out how to tell him that the default assignment on this probably isn't a good practice?
<Uncle_Cid>
or why it isn't
<Uncle_Cid>
it seems like an out of the box thing someone doesn't normally do because I'
<Uncle_Cid>
m not really getting search results for what I am looking for lol
mossplix has joined #ruby
bocaneri has quit [Remote host closed the connection]
apotheon has quit [Ping timeout: 246 seconds]
cliluw has joined #ruby
<adam12>
Uncle_Cid: I don't see instance variables used that often as a default assignment but often a method call that would be backed by the instance variable. So it would be OK in my books.
sagax has quit [Ping timeout: 256 seconds]
sagax has joined #ruby
apotheon has joined #ruby
<Uncle_Cid>
heard that
imode has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
snuz has quit [Read error: Connection reset by peer]
snuz_ has joined #ruby
rmnull has joined #ruby
<rapha>
adam12: what does it mean for a method call to be "backed" by the (a?) instance variable?
<Uncle_Cid>
He's assuming whoever is writing code using this method would have defined the default value before calling the method
<Uncle_Cid>
You're not really using case for it's benefits
wymillerlinux has quit [Quit: wymillerlinux]
<havenwood>
Roelof20: Omit those `return`s.
<adam12>
rapha: Ruby accessors use an instance variable to provide the value. So instead of seeing `node = @root`, I might have seen `node = root`, with `root` being an accessor. Or a method.
<adam12>
rapha: The method being `def root; @root; end` or something, but that's easily a reader.
<adam12>
rapha: I mostly dislike instance variables because of the way they'll return `nil` for undefined instance variables. I'll prefer a local or a method call almost every time. Probably why I rarely see an instance variable used as a default in a method definition.
<havenwood>
Roelof20: .rs is a Rust extension. ;P
<havenwood>
Roelof20: .rb for Ruby.
<Roelof20>
oke, all the returns are deleted
<Roelof20>
and the file has a extension of rb. Typo when making a gists
<rapha>
adam12: wait, so you also try to use attr_accessor as little as possible?
rmnull has joined #ruby
<havenwood>
Roelof20: Just put a space after that comma!
<havenwood>
Roelof20: (x,y)
rmnull has quit [Client Quit]
<havenwood>
Roelof20: (x, y)
<adam12>
rapha: No. I try to use attr_* as _much_ as possible (compared to an instance variable).
<havenwood>
I use instance variables. :P
<adam12>
rapha: If it comes down to @foo or private attr_reader :foo, I'll probably use the latter almost every time.
<adam12>
rapha: Rubocop helps with this to some degree, as does ruby -w.
<havenwood>
Roelof20: It now reads pretty well, yeah?
<Roelof20>
yep, it is still working and the tests are still green
<adam12>
Instance variables are probably faster in some minor way.
<Roelof20>
havenwood
<adam12>
You can't use the extract method refactor pattern as easy tho.
Bounga has quit [Ping timeout: 260 seconds]
<rapha>
adam12: okay, so you're fine with instance variables "protected" by accessor methods, is what I understood now?
<Roelof20>
and I think I will install ruby tomorrow again with ruby installer
<Roelof20>
this makes me crazy
<adam12>
rapha: Yeah. Nothing wrong with instance variables, but I prefer them to normally be in `initialize` and nowhere else. If I need them, they are through an accessor or another method call.
<havenwood>
Roelof20: I'm going to burn these BLTs. AFK!
<Roelof20>
BLT ??
<Roelof20>
so maybe tomorrow I have to install everything with rubyinstaller or look again to do it on docker
<al2o3-cr>
Roelof20: bacon, lettuce and tomato
apotheon has joined #ruby
<Roelof20>
sorry, still do not make sense to me. maybe because english is not my mother language
<Uncle_Cid>
adam12 I would probably argue against assigning default value with an instance variable because perhaps it's not clear
<Uncle_Cid>
what is really going on there
<Uncle_Cid>
or what a good default value ACTUALLY is
<Roelof20>
what is then a better way. Do the calculation in the score function ?
<Roelof20>
adam12 Uncle_Cid
cnsvc has joined #ruby
schne1der has quit [Ping timeout: 256 seconds]
* Uncle_Cid
shrugs
<Uncle_Cid>
idk what youg uys got going on lol
vondruch has quit [Ping timeout: 246 seconds]
<havenwood>
Roelof20: Normally I'd suggest that you think about what internal state you need to store, if any.
asfas has joined #ruby
<havenwood>
Roelof20: The #distance is a reader, so it can't change. That means the #score value can just be memoized (remembered and served up again, if asked).
<asfas>
Hey guys! Question - I have a shitty deeply nested hash (which I have no control over) which has a certain key either, 4 levels down or 5 levels sometimes. How do I write a block of code that handles this without having to dirty 4 nested loops and then handle the case for the 5th if the key isn't found in the 4th?
<havenwood>
Roelof20: Since no internal state matters, this could just be an actual module function. Happy to discuss.
<havenwood>
Roelof20: Or you could pretend it does matter, and practice memoizing.
<havenwood>
asfas: Are you already using #dig?
<havenwood>
asfas: Sounds like #dig twice.
jayx has joined #ruby
<asfas>
I am using dig, but the resultant code is pretty bad. It is 4 levels down sometimes and 5 and sometimes 3. How do I repeat this pattern? Could you please give an example? Thanks!
<havenwood>
asfas: Could you show us a small example hash of the 4 or 5 levels down and the desired result?
<havenwood>
Or a 1 or 2 levels down paired down example?
<havenwood>
Roelof20: You're giving two arguments and no stored internal value of the class matters, so a module function makes sense unless something is asking the Dart score multiple times.
<havenwood>
Roelof20: So basically, make it an actual function in a module or if it's a class, go ahead and calculate the score when it's initialized.
<havenwood>
Roelof20: Sometimes these problems are contrived, and the goal is just to match the interface, which might not be a particularly sensible interface.
<leftylink>
hmm. my thought would be to successively descend into one layer of Rows+Row, once there are no more Rows+Row to descend into, take the ColData from there
<havenwood>
leftylink: yeah, I was contemplating a recursive flipfloppy type thing too
<havenwood>
hard to tell what the rules are exactly
<leftylink>
if you thought of recursion first, that is interesting, since I also thought of it first. then I had to consider whether to explicitly mention that in my suggestion
<havenwood>
leftylink: you just made me consider whether you were recursing as a joke
<havenwood>
now I'm wondering if I'm recursing as a joke
<asfas>
recursion sounds like a feasible solution
Roelof20 has quit [Ping timeout: 245 seconds]
<asfas>
The structure always remains this -> (Rows, Row) -> Array -> 0 -> (Rows, Row) -> Array -> 0 -> (Rows, Row) -> Array.. at some point you find ColData there
<leftylink>
I chose not to explicitly mention recursion since I decide to leavce it up the implementor's choice whether to use recursion or not to achieve "successively descend"
<asfas>
I made it! Thank you so much havenwood and leftylink! For some reason, I didn't even consider recursion
jetchisel has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
schne1der has quit [Remote host closed the connection]
schne1der has joined #ruby
AndreYuhai has joined #ruby
<AndreYuhai>
How many jobs can I submit into sidekiq queue? What's the upper limit