Open in app

Sign in

Write

Sign in

ΛGHYΛD
ΛGHYΛD

2 Followers

Home

About

May 26, 2016

Looking for help or consultation for your project? Or having questions?

Looking for help or consultation for your project? Or having questions? Feel free to drop me a line here or visit www.aghyad.com

Profile

1 min read

Looking for help or consultation for your project? Or having questions?
Looking for help or consultation for your project? Or having questions?
Profile

1 min read


May 25, 2016

Procs on the Go

Is the line of code below valid Ruby code? -> (a) {p a}[“Hello world”] Yes, it’s valid. Here’s how to understand what it does: The -> operator is often called the “stabby proc”, and in ruby, it creates a new Proc, which is one of Ruby’s function types. It’s also…

Ruby

2 min read

Ruby

2 min read


May 25, 2016

Manipulating Strings

Given: x = “hello” Can you explain the difference between: x += “ world” and x.concat “ world” Well, the += operator re-initializes the variable with a new value, so a += b is equivalent to a = a + b. Therefore, while it may seem that += is mutating the value, it’s actually creating a new object and pointing the the old variable to that new object. This is perhaps easier to understand if written as follows:

Programming

1 min read

Programming

1 min read


May 25, 2016

Methods & Expressions

Consider: def foo(x) puts x * 2 end puts foo 5 # → 10 puts foo(5) # → 10 puts foo (5) # → 10 Now consider: def bar(y, z) puts y + z end puts bar 1, 2 # → 10 puts bar(1, 2) # → 10 puts bar (1, 2)…

Programming

2 min read

Methods & Expressions
Methods & Expressions
Programming

2 min read


May 25, 2016

The power of “super”

What is the difference between calling super and calling super()? A call to super invokes the parent method with the same arguments that were passed to the child method. An error will therefore occur if the arguments passed to the child method Also, a call to super doesn’t match what the parent is expecting. But a call to super() invokes the parent method without any arguments, as presumably expected. As always, being explicit in your code is a good thing.

Programming

1 min read

The power of “super”
The power of “super”
Programming

1 min read


May 25, 2016

to_proc in iterators

In Ruby code, you quite often see the trick of using an expression like: array.map(&:to_s) as a shorthand form of: array.map { |element| element.to_s } But, how exactly does it work? When a parameter is passed with & in front of it (indicating that is it to be used as a block), Ruby will call to_proc on it in an attempt to make it usable as a block. Symbol#to_proc quite handily returns a Proc that will invoke the method of the corresponding name on whatever is passed to it, thus enabling our little shorthand trick to work.

Programming

1 min read

Programming

1 min read


May 13, 2016

A tale of “&&” and “||”

In ruby, the operators “&&” and “||” in ruby statements (not if-stmts) have some special properties. Let’s see how: stmt1 && stmt2 returns the first falsey result, or if no falsey’s found, returns the last truthy result example: ‘hello’ && ‘bye’ # => ‘bye’ ‘hello’ && false # => false …

Ruby

2 min read

A tale of “&&” and “||”
A tale of “&&” and “||”
Ruby

2 min read


May 13, 2016

On testing rake tasks

Warning: The following post is my personal opinion. If you feel I’m wrong or you disagree with me, please reply to this post and I’ll will be so glad to read your opinions. Imagine with me for a second. One shiny morning, while working on your amazing project, written in…

Ruby On Rails

2 min read

Ruby On Rails

2 min read

ΛGHYΛD

ΛGHYΛD

2 Followers
Following
  • Jeff Bullas

    Jeff Bullas

  • Nir Eyal

    Nir Eyal

  • Tobias van Schneider

    Tobias van Schneider

  • Julie Zhuo

    Julie Zhuo

  • Hunter Walk

    Hunter Walk

See all (59)

Help

Status

About

Careers

Blog

Privacy

Terms

Text to speech

Teams