<TvL2386>
hey guys, question about documentation of code: Since ruby always returns the result of the last evaluation in a method, something may be returned that the author didn't intend to or simply is not interested in. Should I then document what it returns, or should I document it returns nothing?
<TvL2386>
I feel like I should change all my methods to return nil if I'm going to document that
<TvL2386>
but then that makes me sad
<ZzZombo>
Document the actual result type. Put `nil` as the last statement where necessary.
<TvL2386>
thx
<TvL2386>
no surprises :)
<ZzZombo>
That's what I stick to. I always make sure the last expression produces the expected result, use explicit `return`, or put `nil` down at the end.
<ruby[bot]>
old_relik: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
venmx has joined #ruby
<TvL2386>
yes it can
<TvL2386>
first of all I would do "if condition? or another_condition?"
<TvL2386>
because the body is identical
<old_relik>
sorry made a mistake, the body is actually not identical
<TvL2386>
lol
<TvL2386>
anyway: it looks fine and small to me
Mortomes|Work has joined #ruby
RougeR has joined #ruby
old_relik has quit [Quit: Page closed]
apeiros_ has joined #ruby
Guest61135 has joined #ruby
jottr has joined #ruby
apparition has joined #ruby
Guest61135 has quit [Client Quit]
masterasia has joined #ruby
<masterasia>
if I reopen a class, what happens to everything existing in it?
<masterasia>
does my new code essentially get appended to the end?
<ruby[bot]>
masterasia: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
<apeiros_>
masterasia: nothing happens. it will remain.
apeiros_ is now known as apeiros
<masterasia>
Does the code get added to the beginning or end?
<apeiros>
and yes, it's just as if you'd not closed the class and added that code at the end
<apeiros>
so if you reopen a class and define a method again, last one wins
<masterasia>
It is important, specifically for before_filters in rails controllers
lxsameer has joined #ruby
<masterasia>
thanks apeiros
<masterasia>
is this documented anywhere?
<masterasia>
or just something you know based on experience
<masterasia>
I guess I could find out by digging into the implementation details
<apeiros>
I think it is documented somewhere. no idea where, though. Been a while since I learned that :D
bijan_ has quit [Remote host closed the connection]
bijan_ has joined #ruby
bijan_ has quit [Read error: Connection reset by peer]
bijan_ has joined #ruby
bijan_ has quit [Ping timeout: 252 seconds]
tjbp has joined #ruby
alem0lars has quit [Remote host closed the connection]
alem0lars has joined #ruby
bijan_ has joined #ruby
bijan_ has quit [Read error: Connection reset by peer]
bijan_ has joined #ruby
chichou has joined #ruby
bijan_ has quit [Read error: Connection reset by peer]
apeiros has quit []
tdy has quit [Ping timeout: 272 seconds]
tristanp has joined #ruby
marz_d`ghostman has joined #ruby
<marz_d`ghostman>
What's a good ORM for plain ruby?
bijan_ has joined #ruby
deathwishdave has joined #ruby
tristanp has quit [Ping timeout: 272 seconds]
bijan_ has quit [Read error: Connection reset by peer]
bijan__ has joined #ruby
chichou_ has joined #ruby
bijan__ has quit [Read error: Connection reset by peer]
chichou has quit [Ping timeout: 245 seconds]
<TvL2386>
marz_d`ghostman: probably depends on which backend you're using
<TvL2386>
marz_d`ghostman: I'm only used to activerecord though
<TvL2386>
marz_d`ghostman: for plain ruby I mostly use mysql2, but that's not an ORM
<marz_d`ghostman>
TvL2386: hmmm I'm looking into trying new technology. Perhaps MongoDB
<marz_d`ghostman>
TvL2386: Nah, I think I'll stick with MySQL and use activerecord
<TvL2386>
marz_d`ghostman: sounds cool! My next little rails project will also use mongodb (mostly for learning purposes)
alem0lars has quit [Ping timeout: 246 seconds]
bijan_ has joined #ruby
ZzZombo has quit [Read error: Connection reset by peer]
Puffball_ has joined #ruby
bijan__ has joined #ruby
bijan_ has quit [Ping timeout: 252 seconds]
<chichou_>
marz_d`ghostman: did you try sequel?
<marz_d`ghostman>
chichou_: I tried searching for one, it appears activerecord is the most popular
blackmesa has joined #ruby
<TvL2386>
sequel extends activerecord
<chichou_>
I think you meant activemodel?
<TvL2386>
arg... I'm sorry, that's not correct... I was thinking about `squeel`
<chichou_>
the same letters in different orders :P
<TvL2386>
yeah lol :)
t0adst00l has joined #ruby
<chichou_>
and I wasn't right either, it doesn't even extend activemodel but it's just a development dependency somehow
gnufied has joined #ruby
Sembei has quit [Max SendQ exceeded]
Sembei has joined #ruby
blackmesa has quit [Ping timeout: 250 seconds]
gnufied has quit [Ping timeout: 252 seconds]
bijan__ has quit []
apeiros_ has joined #ruby
AJA4350 has joined #ruby
esrse has quit [Ping timeout: 245 seconds]
Mortomes|Work has quit [Ping timeout: 252 seconds]
GodFather has joined #ruby
xfbs has joined #ruby
InfinityFye has joined #ruby
bijan_ has joined #ruby
ZzZombo has joined #ruby
za1b1tsu has quit [Ping timeout: 252 seconds]
nfk has joined #ruby
za1b1tsu has joined #ruby
lupine has quit [Remote host closed the connection]
<nfk>
i can't believe i spent like 4 hours yesterday debugging firefox csp, sinatra, rack-protection and my app when the cause was NoScript running in my firefox...
lupine has joined #ruby
tristanp has joined #ruby
tristanp has quit [Ping timeout: 252 seconds]
<donofrio>
nfk, don't beat yourself up too much, next time "Private browsing" for your testing
bmurt has joined #ruby
bijan_ has quit [Remote host closed the connection]
alireza has joined #ruby
<alireza>
Hey Ammigos!
<alireza>
I have a promotion base class
<alireza>
which has two methods, `eligible?` and `perform`
<nfk>
donofrio, i obviously run noscript inside it as well
<nfk>
after all, i do about half of my googling in private or incognito just so that algorithm didn't start spamming me with lawnmover or lisp framework results
clemens3 has joined #ruby
<alireza>
How can I call `return order.total unless eligble?(order)` before children logic
<nfk>
some easy things first: 1) it's good that you're using @percent to indicate that it's a percentage but if you're actually doing math on it, it's much safe to just keep it as a float and format it as a percentage only when shown in a human friendly manner
Fusl has quit [Ping timeout: 256 seconds]
bijan_ has quit [Ping timeout: 252 seconds]
chouhoulis has joined #ruby
<alireza>
nfk: thanks for your consideration
<nfk>
that way if stuff goes sideways you'll end up with 0.2% discount where it should have been 20% instead of substacting 20, because someone forgot to do the conversion
<alireza>
nfk: but I don't get where's the spagetti?
<nfk>
alireza, hey, you have to be careful with money, if you bill me €-5, i'll take them and the product, thank you
Fusl has joined #ruby
za1b1tsu has joined #ruby
SolarAquarion has joined #ruby
<alireza>
nfk: actually percent is for that, when you say 10 percent you mean 0.1
<alireza>
so I can abstract out percentage logic outside or just provide a simple keyword argument which indicates that
<alireza>
it's just a simple test
<nfk>
alireza, it's just a good practice, when it comes to money, to avoid using percentage as your internal representation
<alireza>
nfk: for sure
<alireza>
but my question is how to call `return order.total unless eligible?(order)` in parent class
<nfk>
alireza, and i'm sharing my opinion on how i'd avoid some pitfals, speaking of which, i would have order.base_total and order.total
<alireza>
nfk: yeah I appricate that
<nfk>
that way, again, if stuff goes sideways, you won't end up repeatedly applying the same discount
<alireza>
yeah, I need line itmes
<alireza>
*items
<alireza>
and a base total
<alireza>
but first I'm going to elminate `return order.total unless eligible?(order)` in children classes
<nfk>
you'd likely also want to do all your discounts in one place (i.e. pass in order and some hash of all potentially applicable discounts)
bijan_ has quit [Ping timeout: 252 seconds]
<nfk>
alireza, i think that if you redo your discounting to all happen in one place, then you won't have that issue in the first place but that's just me
<nfk>
yeah, i see a lot of abstraction with very little code, which is why i called that code spaghetti
bijan_ has joined #ruby
<nfk>
alireza, my gut feeling without considering that spaghetti is that when you call super the self it's being called on is not what you think it is but that's just my first hunch
<alireza>
nfk: yeah I just realized that
<alireza>
nfk: I should consider something like before_action
Puffball_ has quit [Remote host closed the connection]
Puffball has joined #ruby
jottr has joined #ruby
thy0 has joined #ruby
MaiconVieira has joined #ruby
chouhoulis has quit [Remote host closed the connection]
gnufied has joined #ruby
thy0 has quit [Quit: TTFN]
thy0 has joined #ruby
xtsee has quit [Ping timeout: 252 seconds]
t0adst00l has quit [Ping timeout: 256 seconds]
jottr has quit [Ping timeout: 245 seconds]
bijan_ has quit [Ping timeout: 250 seconds]
kapil___ has joined #ruby
t0adst00l has joined #ruby
bijan_ has joined #ruby
jottr has joined #ruby
micabot has joined #ruby
bijan_ has quit [Ping timeout: 252 seconds]
alem0lars has joined #ruby
aufi has quit [Ping timeout: 245 seconds]
bijan_ has joined #ruby
blackmesa has joined #ruby
BrainWork has joined #ruby
<BrainWork>
hi. i know absolutely nothing about ruby, but i am a programmer with many years of experience in other languages such as php, C++, even assembler. What is a good resource as a 'crib note' to kickstart some starting knowledge in ruby please?
bijan_ has quit [Ping timeout: 252 seconds]
<BrainWork>
i have no goal except to learn the basics of another language relatively quickly
<BrainWork>
there's lots of documentation out there but much of it is either a dry reference manual or assumes beginner status
snickers has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bijan_ has joined #ruby
jottr has quit [Ping timeout: 252 seconds]
tristanp has joined #ruby
<chichou_>
BrainWork: online material only or books as well?
jottr has joined #ruby
tristanp has quit [Ping timeout: 245 seconds]
<nfk>
BrainWork, well, if you're just fooling around, maybe try http://rubykoans.com/
<nfk>
i remember having quite a bit of fun with those when i started, though it was some online interpreter rather than a set of local files
mynameisdebian has quit [Remote host closed the connection]
lxsameer has joined #ruby
lxsameer has quit [Ping timeout: 246 seconds]
RougeR has joined #ruby
lxsameer has joined #ruby
blackmesa has quit [Ping timeout: 264 seconds]
snickers has joined #ruby
lxsameer has quit [Ping timeout: 252 seconds]
johnny56 has quit [Read error: Connection reset by peer]
johnny56 has joined #ruby
lxsameer has joined #ruby
SeepingN has joined #ruby
jottr has quit [Ping timeout: 252 seconds]
lxsameer has quit [Ping timeout: 245 seconds]
SeepingN has quit [Read error: Connection reset by peer]
SeepingN has joined #ruby
nowhere_man has quit [Ping timeout: 252 seconds]
lxsameer has joined #ruby
sanscoeur has joined #ruby
ua has quit [Ping timeout: 252 seconds]
<nfk>
Oh, derp, I'm testing my webapp on both firefox and google chrome and i'm getting different colors!
deathwishdave has joined #ruby
lxsameer has quit [Ping timeout: 244 seconds]
venmx has quit [Ping timeout: 252 seconds]
lxsameer has joined #ruby
mikecmpbll has joined #ruby
weaksauce has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
blackmesa has joined #ruby
lxsameer has quit [Ping timeout: 272 seconds]
<nfk>
On one hand I feel like pursuing this rabbit but I know that color management is gonna be one hellish rabit hole. Especially on linux. After all, all my profiles (other than my mpv vo_gpu one) is set to a test profile with wacky colors - if anything was capable of picking them up, I'd immediately notice that
<nfk>
s/is/are/
SeepingN has quit [Disconnected by services]
blackmesa1 has joined #ruby
SeepingN_ has joined #ruby
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
blackmesa has quit [Ping timeout: 252 seconds]
jottr has joined #ruby
lxsameer has joined #ruby
bmurt has joined #ruby
tdy has joined #ruby
TheBloke has quit [Ping timeout: 240 seconds]
jottr has quit [Ping timeout: 246 seconds]
lxsameer has quit [Ping timeout: 252 seconds]
deathwishdave has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<havenwood>
AndreYuhai: Those ^ should get you on the right track.
<AndreYuhai>
havenwood: Oh thank you! :) I didn't even know it was called like so.
weaksauce has joined #ruby
faitswulff has joined #ruby
venmx has joined #ruby
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #ruby
akem has quit [Ping timeout: 252 seconds]
roshanavand has joined #ruby
akem has joined #ruby
knight33 has joined #ruby
sanscoeur has quit [Ping timeout: 252 seconds]
faitswulff has quit [Remote host closed the connection]
jottr has joined #ruby
blackmesa1 has quit [Ping timeout: 250 seconds]
blackmesa1 has joined #ruby
jottr has quit [Ping timeout: 244 seconds]
sanscoeur has joined #ruby
faitswulff has joined #ruby
prometheus_falli has quit [Ping timeout: 256 seconds]
Dirak has joined #ruby
<Dirak>
!learn
prometheus_falli has joined #ruby
code_zombie has joined #ruby
eckhardt has joined #ruby
<Dirak>
Hi, I'm a JS dev, and I need to learn Ruby for a company I'm interviewing with. What are the legit resources for learning Ruby on the level of 'you don't know js' and 'eloquent js'
mynameisdebian has quit [Ping timeout: 260 seconds]
<Dirak>
My friend told me Ruby is a way of thinking and a philosophy so I need my reading material to redpill me
jottr has joined #ruby
<nfk>
and oz already linked you with pretty much the stuff everyone learns from (obviously from the ones that fit their taste)
<nfk>
as for the ones you listed, i have no idea about their teaching style as i learned js the hard way - by writing application code before the days of node
<nfk>
ecmascript as a language is so simple that i'm always baffled by people who need to learn it
<Dirak>
w0w there are some serious caveats to JS u just gotta know
<Dirak>
like that the max int is 2^58. And that callbacks take the form (err, data) as their signature
<nfk>
i find it pretty difficult to max out anything that large
jp has joined #ruby
<nfk>
also i was under impression that 58 usable bits for memory addresses on 64 bit arches was an implementation approach rather than a language feature
<Dirak>
I have a friend who works at an ecommerce company. Every million transactions or so, their company magically lose a penny cuz of JS's Number imprecision. They call it the JS tax
<CPngN>
yet they use JS
<CPngN>
cuz silly
<nfk>
couldn't they actually have BigInt implemented in JS?
jottr has quit [Ping timeout: 260 seconds]
<havenwood>
typeof 42n; #=> 'bigint'
lomex has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<nfk>
actually, how would they end up losing money? it was a bit less than I thought - just mere 2.8e17 but that's seems to be enough to track the world's economy at a fraction of penny/cent precision
<nfk>
*that
roshanavand has quit [Ping timeout: 250 seconds]
roshanavand has joined #ruby
blackmesa has joined #ruby
nowhere_man has quit [Ping timeout: 252 seconds]
jp has joined #ruby
evdubs_ has joined #ruby
jottr has joined #ruby
nowhere_man has joined #ruby
evdubs has quit [Ping timeout: 252 seconds]
jottr has quit [Ping timeout: 272 seconds]
faitswulff has quit [Remote host closed the connection]
nine_milli_ has joined #ruby
moei has quit [Quit: Leaving...]
cagomez has joined #ruby
cagomez has quit [Read error: Connection reset by peer]
<nine_milli_>
is php better than ruby?
cagomez has joined #ruby
cagomez has quit [Read error: Connection reset by peer]
<oz>
nine_milli_: it depends. ;)
<nfk>
don't feed the troll
cagomez has joined #ruby
cagomez has quit [Read error: Connection reset by peer]
<CPngN>
it depends. either "no", or "hell no!"
cagomez has joined #ruby
cagomez has quit [Read error: Connection reset by peer]
<oz>
nfk: oh, true that. :)
cagomez has joined #ruby
cagomez has quit [Read error: Connection reset by peer]
cagomez has joined #ruby
cagomez has quit [Read error: Connection reset by peer]
<nine_milli_>
what are the advantages of ruby over php if any?
apeiros_ has quit [Ping timeout: 252 seconds]
<nine_milli_>
also was ruby made by a 400lb man in a bed somewhere?
jolamb has joined #ruby
Eiam has joined #ruby
lxsameer has joined #ruby
nine_milli_ has left #ruby ["Leaving"]
xtsee has joined #ruby
lxsameer has quit [Ping timeout: 260 seconds]
roshanavand has quit [Quit: Lost terminal]
jolamb has left #ruby ["WeeChat 1.9.1"]
jp has quit [Ping timeout: 252 seconds]
weaksauce has quit [Ping timeout: 272 seconds]
<baweaver>
!troll nine_nilli_
<ruby[bot]>
baweaver: Could not find user with nick "nine_nilli_"
<baweaver>
!troll nine_milli_
<baweaver>
There we go.
<Dirak>
Does every object in Ruby have the method .nil?
snickers has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jottr has joined #ruby
<nfk>
if you meant nil?, then... you might be able to not have one if you essentially uprooted or replaced the entire runtime
<nfk>
but as things stand, yes
<nfk>
afaik
jottr has quit [Ping timeout: 245 seconds]
faitswulff has joined #ruby
<nfk>
Dirak, oh, i just realised i automatically removed the ? from .nil because you were asking a question, sorry
faitswulff has quit [Ping timeout: 252 seconds]
kapil___ has quit [Quit: Connection closed for inactivity]
bmurt has joined #ruby
apeiros_ has joined #ruby
<Dirak>
how come the object_id of numbers follows the pattern 2n + 1?
<nfk>
my gut feeling is that it just might be to avoid a circular definition, because object_id has to return an object?
nowhere_man has quit [Ping timeout: 252 seconds]
<Dirak>
oh wtf << isn't a bitwise operator in Ruby?
<nfk>
is it even a bitwise operator in C++ is my first question
<nfk>
anyway, ObjectSpace._id2ref 2
<nfk>
try that
<nfk>
Dirak, anyway, my bad, << is the bitwise operator, and it's also doing the same job in ruby: a = 1; puts a; a <<= 2; puts a
<Dirak>
ooh gotcha
<nfk>
what you might be confused about is the fact that it's just a method (just like in C++), which means that you can define your own /, + and, yes, <<
blackmesa has quit [Quit: WeeChat 2.2]
<Dirak>
I like << syntax to push into an array
gnufied has quit [Ping timeout: 252 seconds]
DTZUZO_ has quit [Ping timeout: 272 seconds]
reber has quit [Remote host closed the connection]
tdy has quit [Ping timeout: 240 seconds]
jp has joined #ruby
mike11 has quit [Quit: Leaving.]
ndr0s has joined #ruby
meinside has quit [Quit: Connection closed for inactivity]
vondruch_ has joined #ruby
RiPuk has joined #ruby
faitswulff has joined #ruby
jasmith has joined #ruby
vondruch has quit [Ping timeout: 246 seconds]
vondruch_ is now known as vondruch
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Puffball has quit [Remote host closed the connection]
hays_ has joined #ruby
nowhere_man has joined #ruby
Puffball has joined #ruby
DTZUZO_ has joined #ruby
<hays_>
anyone who uses rubocop--is it fair to say that driving the number of "offenses" to zero is not usually practicable
<hays_>
I'm finding some cases where.. it doesn't make sense to make the method shorter, or ABC complexity makes sense
faitswulff has quit [Remote host closed the connection]
Dirak has quit [Ping timeout: 250 seconds]
TomyLobo has quit [Read error: Connection reset by peer]
<marz_d`ghostman>
I'm using dispatch and I have these lines: autocmd FileType ruby let b:dispatch = 'rspec %' nnoremap <F9> :Dispatch!<CR> but I'm getting an erorr: || make: *** No targets specified and no makefile found. Stop.
<marz_d`ghostman>
I can run :Dispatch rspec % fine though
Dirak has joined #ruby
tdy has quit [Ping timeout: 246 seconds]
[Butch] has joined #ruby
za1b1tsu has quit [Ping timeout: 272 seconds]
TheBloke has quit [Ping timeout: 250 seconds]
sameerynho has quit [Ping timeout: 252 seconds]
IanMalcolm has joined #ruby
faitswulff has joined #ruby
<baweaver>
hays_: Depends on how pedantic one wants to be
<baweaver>
I normally set some to warn and some to error
<baweaver>
Difference is what you want to be build-breaking
<hays_>
baweaver: it seems basically impossible to use optparse in a way that won't violate a rubocop rule
<hays_>
since you end up with a big block if you have more than a few args
chichou_ has joined #ruby
IanMalcolm has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
lxsameer has joined #ruby
elphe has joined #ruby
lxsameer has quit [Ping timeout: 252 seconds]
za1b1tsu has joined #ruby
nfk has quit [Quit: Try memory.free_dirty_pages=true in about:config]