# Please explain me this ruby code

**URL:** <https://www.ruby-forum.com/t/please-explain-me-this-ruby-code/59595>\
**Category:** Rails\
**Created:** [May 4, 2006, 2:50pm UTC](https://www.ruby-forum.com/t/please-explain-me-this-ruby-code/59595 "2006-05-04T14:50:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [May 4, 2006, 2:50pm UTC](https://www.ruby-forum.com/t/please-explain-me-this-ruby-code/59595/1 "2006-05-04T14:50:18Z")

</div>

# Hi all, This is small code from typo 2.6.0’s “articles\_helper.rb” file

# def author\_link(article) if config[‘link\_to\_author’] and article.user and article.user.email.to\_s.size\>0 “\<a href=“mailto:#{article.user.email}”\>#{article.user.name}” elsif article.user and article.user.name.to\_s.size\>0 article.user.name else article.author end end

In above code What is the meaning of “config[‘link\_to\_author’]”???  
What is “config” here??  
Please tell me.

Thanx in advance.  
Prash

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [May 4, 2006, 3:14pm UTC](https://www.ruby-forum.com/t/please-explain-me-this-ruby-code/59595/2 "2006-05-04T15:14:47Z")

</div>

> In above code What is the meaning of “config[‘link\_to\_author’]”???  
> What is “config” here??  
> Please tell me.

Well, it looks like a hash name config. I’ve never used Typo, but I  
would venture to guess that it allows you to set some preferences  
which get stored in a hash named config.

-Derrick S.

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [May 4, 2006, 3:17pm UTC](https://www.ruby-forum.com/t/please-explain-me-this-ruby-code/59595/3 "2006-05-04T15:17:58Z")

</div>

Yeah, basically it’s looking up a configuration setting in the admin  
section that says, “does this user want to allow a link to their  
email.” If the setting is set, then the anchor html is written out  
otherwise the just the author’s name is written out.

Michael

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [May 4, 2006, 3:39pm UTC](https://www.ruby-forum.com/t/please-explain-me-this-ruby-code/59595/4 "2006-05-04T15:39:47Z")

</div>

Hello Prashant,

> # This is small code from typo 2.6.0’s “articles\_helper.rb” file
> 
> # def author\_link(article) if config[‘link\_to\_author’] and article.user and article.user.email.to\_s.size\>0 […]
> 
> In above code What is the meaning of “config[‘link\_to\_author’]”???  
> What is “config” here??

config is a method that returns the value of the global variable  
$config.  
(it hides implementation, just like params() gives access to @params)  
$config holds an Configuration instance. The Configuration class derives  
from ConfigManager class that defines a [] method. So $config inherits  
a [] method and can be seen as a hash-like object (not really, because  
[]= method is not implemented). config[key] is a way to access  
to default settings (by default config[‘link\_to\_author’] is false).

All details are in app/models/configuration.rb and  
app/models/config\_manager.rb

```
-- Jean-FranÃ§ois.
```
