Ruby: attr_accessor, attr_reader, attr_writer

Accessors are sometimes known as getters/setters or mutators.

They let you get/set instance variables.

In Ruby attr_reader, e.g.:

attr_reader :age

is equivalent to:

def age



Breaking it down – the :age is a symbol named “age”. Symbols have the feature that any two symbols named the same will be identical (they use the same pointer). 

This is not the same in a string.

This means comparing them is super fast – you just do a pointer comparison.

Also, symbols are immutable – again, not like strings.

So, writing attr_reader :age gets translated into code that returns the instance variable @age.

And, attr_writer :age gets translated to:

def age=(value)

  @age = value


attr_accessor :age

just combines the two. 


Ruby: how the interpreter parses your code

I wasn’t sure exactly how the Ruby code I’d written was being interpreted.

For example, 

class TestClass

def initialize(x = 1)

@x = x


puts “inside the class”


a =

puts “declared an instance”

Now, does this print “inside the class” or “declared an instance” first?

The answer is “inside the class”.

See also this post describing using Ripper to parse code: 

rvm: Permission denied

Getting this error?

$ gem install passenger

Fetching: passenger-4.0.5.gem (100%)

ERROR:  While executing gem … (Gem::FilePermissionError)

    You don’t have write permissions for the /Users/snowcrash/.rvm/gems/ruby-2.0.0-p195 directory.

[scripts (master)]$ ls -ld /Users/snowcrash/.rvm/gems/ruby-2.0.0-p195

drwxrwsr-x  8 root  rvm  272 21 May 16:07 /Users/snowcrash/.rvm/gems/ruby-2.0.0-p195

Changing permissions fixes things:

sudo chown -R <user-here>:<group-here> ~/.rvm/

A StackOverflow discussion on a slightly different aspect:

Rails: Phusion Passenger

Passenger is an application server for Ruby (Rack) and Python (WSGI) apps.

Some notes on installing it:

Ignore the docs that suggest:

$ sudo gem install passenger

$ sudo passenger-install-apache2-module

Instead use:

gem install passenger

should be sufficient and suggests just running:


See also:


Then, paste the LoadModule code it spits out at the end into your Apache conf file.

Test whether Passenger has installed by running:

curl -sI localhost | grep ^Server

and check for the “Phusion_Passenger” signature. E.g. 

Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch Phusion_Passenger/4.0.5 mod_ssl/2.2.22 OpenSSL/0.9.8x

If you need to uninstall Passenger using sudo then:

$ sudo gem uninstall passenger

And a discussion on whether to use rvmsudo or not here:!topic/rubyversionmanager/9dnmAsTiHR4

In short,

suggests using sudo but the rvm page suggests not:


If you get a warning doing the passenger install apache2 module like this:

rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all

Warning: can not check /etc/sudoers for secure_path, falling back to call via /usr/bin/env, this breaks rules from /etc/sudoers. Run:

    export rvmsudo_secure_path=1

Then run:

    export rvmsudo_secure_path=1


rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all

(remember to run rvm requirements afterwards)

On the Mac the Apache conf and restart commands go like this:

[~]$ sudo vim /etc/apache2/httpd.conf

[~]$ sudo apachectl restart

See also: