#ruby - 01 July 2017
« Back 1 day Forward 1 day »
[10:49:37] typeVoid: I'm about to start using JRuby, should I override `puts` or should I define 'println' and use that
[15:09:50] impermanence: can someone remind where that most excellent (somewhat?) curated list of ruby books is on github? It essentially organized the books in terms of difficulty and gave a description of each. I'm having a bit of trouble finding it, but I think it is fairly well known?
[15:13:55] fdsbghdfsgfghsd: im new to ruby, is using method_missing here bad practice or is it clever? https://github.com/nolim1t/btcmarkets-gem/blob/master/lib/nl-btcmarkets.rb
[15:14:37] fdsbghdfsgfghsd: then you can call API requests as such puts b.get_market_BTC_AUD_tick or puts b.get_market_BTC_AUD_orderbook etc
[15:16:32] havenwood: you could skip the if statement and just: @apikey = ENV['btcm_access_key'] || ''
[15:17:41] fdsbghdfsgfghsd: I'm more just asking if him using method_missing here is a smart move or idiotic?
[15:17:55] impermanence: havenwood: heh, yeah that's it. I just finished a lengthy crash course in the very basics of the syntax. So now I know that I know enough Ruby to suck at it. I'm look to "go round two" but I want to do it at a fast pace so I'm probably going to stay away from textbooks or anything super complicated. Any recs?
[15:18:21] ruby[bot]: Ruby community standards recommend using 2 spaces as indentation (see https://github.com/bbatsov/ruby-style-guide#spaces-indentation and https://ukupat.github.io/tabs-or-spaces/).
[15:18:56] havenwood: fdsbghdfsgfghsd: you can `arguments.one?` as a nice optimization of `arguments.length == 1`
[15:18:57] fdsbghdfsgfghsd: Instead of having a function for each type of API call you make them by saying:
[15:19:06] fdsbghdfsgfghsd: then you can call API requests as such puts b.get_market_BTC_AUD_tick or puts b.get_market_BTC_AUD_orderbook etc
[15:19:31] havenwood: fdsbghdfsgfghsd: that method seems overly complex, but it's also a bit hard to read with the combo of spaces and tabs
[15:19:56] havenwood: link with 2-spaces: https://github.com/nolim1t/btcmarkets-gem/blob/master/lib/nl-btcmarkets.rb?ts=2
[15:20:15] fdsbghdfsgfghsd: havenwood: how are API gems usually written then? One function def for each API call?
[15:20:20] havenwood: fdsbghdfsgfghsd: i'd say explicit methods per verb would be simpler and cleaner, that's my hunch
[15:20:52] havenwood: fdsbghdfsgfghsd: yes, you usually see a method per verb then some private implementation detail methods for the guts
[15:21:52] fdsbghdfsgfghsd: havenwood: so something like get_btc_price("aud") would be better then? As in get the BTC price in AUD
[15:25:15] havenwood: fdsbghdfsgfghsd: that seems to be a higher level abstraction, but i'm not familiar with the domain
[15:26:18] havenwood: fdsbghdfsgfghsd: instead of #method missing, just something simple like: def request(verb, url, opts = nil)
[15:29:13] havenwood: The method_missing approach here looks overly clever/convoluted to me. I think more explicit is a good idea. There are only so many verbs. You can only implement those you use or have a fallback for unknown.
[15:30:29] havenwood: impermanence: The Well-Grounded Rubyist, 2nd Edition covers modern Ruby and gives a good grounding.
[15:32:34] impermanence: havenwood: I'm thinking about going with Wicked Cool Ruby Scripts because right now I'm a sysad and it looks like it covers some subtle approaches to scripting. Plus I need to be doing exercises. And I figure I'll just go through the dude's ideas and make my own scripts...thoughts?
[15:32:44] havenwood: impermanence: The Ruby Programming Language (with Sparrows on the cover) covers similar ground to Well-Grounded Rubyist.
[15:33:21] impermanence: havenwood: yes, I have completed Hellow World and am in the middle of doing hamming rn.
[15:46:27] impermanence: havenwood: I guess what I need is a book with exercises that will help me take my syntax game to the next level. A difficult book is probably fine. Does that exist?
[16:08:23] havenwood: Practical Object-Oriented Design in Ruby (POODR) is often recommended. No exercises but it wouldn't be hard to do come up with your own from the examples.
[16:10:02] impermanence: havenwood: I just ordered Well Grounded 2ed AND the Wicked Cool book. Somebody online wrote a scathing review of the second lol because he felt it was dird at windows admins so I bought two books. Thanks again, man! You're always a help.