5 ms·
Show HN: Learn Ruby by Example with Challenges
- chucknelson 13y agoAh, made me think of the good ol' days => http://rubyquiz.com/ http://rubyquiz.com/ Although this is definitely more tutorial-ish.
- marsay 13y agoThe design of the site looks strange to my eyes. Colors and fonts doesn't make sense. I'm no expert on design so I can't explain why.
- chucknelson 13y agoIf you use Sublime Text it looks pretty familiar in the context of ruby code.
- bzalasky 13y agoI don't think that was in reference to the syntax highlighting.
- arikrak 13y agoThanks for the feedback. I'm going to try to improve the design this week.
- bcjordan 13y agoShoot me a quick hello if you'd like a few suggestions, my username at gmail.
- kartikkumar 13y agoGreat! Diving head first into Ruby so this will come in handy.
- cabbeer 13y agoIs there anything like this for Javascript?
- jader201 13y agoI don't know Ruby, but this caught my eye: true.class #=> TrueClass false.class #=> FalseClass Why would they have two different classes (types?) for what I consider values of a boolean/bit type?
- jonahx 13y agohttp://stackoverflow.com/questions/3192978/why-does-ruby-have-trueclass-and-falseclass-instead-of-a-single-boolean-class http://stackoverflow.com/questions/3192978/why-does-ruby-hav...
- al2o3cr 13y agoTrueClass and FalseClass aren't exactly "classes" in the usual sense - for instance, `TrueClass.new` throws a NoMethodError. Under the hood, true and false are singletons - `(1 == 1).object_id` will always be 20. At least in MRI / YARV, that makes booleans much cheaper in terms of memory (a single pointer vs. a pointer + an RObject struct) but means that they don't have their own instance methods. Keeping the classes separate makes it possible to metaprogram additional behavior onto true and false - for instance, the `blank?` method added by ActiveSupport.
- Argorak 13y agoDon't rely on that ;) Ruby 1.9.3 > (1==1).object_id => 2 > (1!=1).object_id => 0
- jeffrwells 13y agoThis might be a fun challenge for experienced rubyists, but I do not think this is a good way to learn Ruby. I only looked at Ruby Basics, but here's my feedback: The challenge is to solve: 'true and 0 && !nil and 3 > 2', but this is not a real-life application. The words 'and' and 'or' should not be used for boolean comparisons, they are intended to be used to join two separate clauses such as "render 'template' and return" in rails. Comparing a number and bang-nil is not good code. This could actually come to be if you were doing something like: "object.value && !object.value". However, you wouldn't ever want to hardcode "0 && !nil". If you were really checking for nil, you should use "!object.nil?" I'm afraid that these challenges will teach bad code techniques to newbies who don't know the difference. But again, as someone with more familiarity with Ruby, I think these types of challenges are fun, but if that is the goal there is no need for the tutorial beforehand.
- arikrak 13y agoThanks. The challenge was meant as a way to review the different booleans, instead of 'real code'. I added a warning, but I'll see if other code would be better.
- Argorak 13y agoThe biggest problem is that the interesting part about this challenge (different precendence) is rather advanced to beginners and is _not even touched_ in the preceding parts.
- SnacksOnAPlane 13y ago> The words 'and' and 'or' should not be used for boolean comparisons, they are intended to be used to join two separate clauses such as "render 'template' and return" in rails. Is that true? Because I found a bug in our code recently that was in a line like render_error and return where the return was never getting called because render_error returned false. I don't understand why you would write code like that when you could simply write: render_error return and not have to deal with thinking about whether render_error could ever return a falsey value.