bolt githublinkedinPage 1Created with Sketch. spots swoosh target triangle-icon twilio twitterweave

5 Things You Didn’t Know About Ruby

Ilya December 06, 2017

When playing around with Ruby you quickly realise that it is full of fun tricks. Here a few that I’ve come across and wanted to share with you.

1. upcase! method. Have you ever come across this method? Do you know how it really works? Are you sure? Ok, let’s check.


Bob

Why did the last line return a nil? You will find a trick in the very last lines of the code.


Bob2

So the method will return a nil unless a string has been modified. Strange, but you should know that! The downcase! and capitalize! methods have the same behaviour.

2. When you call self in irb or a rails console main is returned and it is an instance of Object class but main is undefined which is really interesting.


Bob3

You should definitely check out this article to learn more about Top-Level.

3. Usually we use a dot “.” to call a method but you can also use double colon “::” to achieve the same results!


Bob4

Weird, but it really works.

4. Question marks will help you generate a single char in Ruby.


Bob5

You will get a SyntaxError if you try to generate more than one char.

I’m not sure that you will use it in your real projects... but it's fun!

5. Last but not least, here’s a short way to invoke a lambda with params. Nifty, right?


Bob6

I hope that this short guide has uncovered something new for you. Ruby is a powerful language and it has countless tricks, so make sure to code and have fun!

THINK

out loud

We think out loud on our blog. We share our views on coding, remote work and post regular insights into the freshest tech industry news.

Want more? Join our mailing list.

    DVELP

    WORK WITH US.

    Client Engagement

    +44 (0) 20 31 37 63 39

    [email protected]

    So, how can we help you?

    Live chat