# ABS |ruby|

**URL:** <https://www.ruby-forum.com/t/abs-ruby/95117>\
**Category:** Ruby\
**Created:** [January 13, 2006, 8:40am UTC](https://www.ruby-forum.com/t/abs-ruby/95117 "2006-01-13T08:40:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [January 13, 2006, 8:40am UTC](https://www.ruby-forum.com/t/abs-ruby/95117/1 "2006-01-13T08:40:06Z")

</div>

Quick question,

In math the absolute value is typically  
the double pipe:  
|x| = 27

This reminds me stuff like:  
Stuff.each { |x| puts 'hello '+x }

Are these two related in any way?  
I dont really see why they would be related but thought it was an  
interesting coincidense nonetheless.

---

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [January 13, 2006, 10:22am UTC](https://www.ruby-forum.com/t/abs-ruby/95117/2 "2006-01-13T10:22:34Z")

</div>

Alex C. wrote:

> In math the absolute value is typically  
> the double pipe:  
> |x| = 27
> 
> This reminds me stuff like:  
> Stuff.each { |x| puts 'hello '+x }
> 
> Are these two related in any way?

No, this is just syntactic sugar. It’s a placeholder for the iteration  
variable. abs is a method in Numeric.

Christer

---

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [January 13, 2006, 10:39am UTC](https://www.ruby-forum.com/t/abs-ruby/95117/3 "2006-01-13T10:39:02Z")

</div>

In math we also have the set-notation like:  
A = { a | a \> 0 }  
which means something like: A is set of elements,  
greater then 0… and so on. This could also  
be read similar to block-syntax. We get a set of elements  
on which we perform some operations (like map+lambda  
call in funcional languages, anonymous function +  
set of elements).  
regards.

---

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [January 13, 2006, 12:28pm UTC](https://www.ruby-forum.com/t/abs-ruby/95117/4 "2006-01-13T12:28:17Z")

</div>

On 1/13/06, Alex C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In math the absolute value is typically  
> the double pipe:  
> |x| = 27
> 
> This reminds me stuff like:  
> Stuff.each { |x| puts 'hello '+x }
> 
> Are these two related in any way?

IIRC, the block syntax in Ruby is reminiscent to Smalltalk syntax,  
which used blocks like this:

[:x | Transcript show: 'hello ', x] “the equivalent of Ruby  
block { |x| puts 'hello '+x }”

and used | vars | to declare some temporary variables in a piece of  
code.

| x y |  
^ x + y

Square brackets are not square anymore (as they are used in Ruby for  
indexing purposes - C inheritance). The odd variable names with  
markers (:x) were replaced by the delimited block of names (| x |) and  
voilà.  
Regards,  
Adriano.
