Tagged: Ruby

August 7th, 2010

map_by_method and awsome_print

I have been playing with some of the gems I installed for my rvm rubies, and the first couple I have looked at are pretty simple – map_by_method and awsome_print.

My trivial code snippet is here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env ruby

# Trivial class with name and gender methods
class Person
  attr_reader :name, :gender

  def initialize(name, gender)
    @name, @gender = name, gender
  end
end

require 'rubygems'
require 'map_by_method'
require 'ap'

people = [ Person.new('Mike', 'M'), Person.new('Derek', 'M')  ]
ap people.map_by_name
ap people.map_by_name_and_gender

Other blog posts about these gems include http://rpheath.com/posts/246-map-by-method-gem and http://www.rubyinside.com/awesome_print-a-new-pretty-printer-for-your-ruby-objects-3208.html

July 24th, 2010

cider, rvm, and homebrew

The rails installed by cider is a rails 3 beta. As I want to play with some of the examples for rails 2 I thought I should get the most recent ruby 1.8.7 and try to use rvm’s gem sets to get myself a rails 2 world set up

brew install `brew outdated`
rvm install ruby-1.8.7-p299
rvm --default ruby-1.8.7-p299

Was my first step to this, but when I tried irb this is what I saw:

ratdog:~ mike$ irb
no such file to load -- map_by_method
ruby-1.8.7-p299 > q

The cause of this was my ~/.irbrc which had been set up, and which has a whole bundle of useful gems added into it. Most of these are worth a post by themselves, but the suspects were:

  • map_by_method
  • what_methods
  • awesome_print
  • net-http-spy
  • hirb
  • looksee
  • wirble
  • sketches

I set up an rvm gemset and started installing gems:

rvm gemset create rails238
rvm ruby-1.8.7-p299@rails238
gem install map_by_method what_methods awesome_print net-http-spy hirb looksee wirble sketches
gem install rails -v 2.3.8
rvm --default ruby-1.8.7-p299@rails238

All appeared to go well, until I tried navigating to a demo appliction and look at the environment on the default splash screen, which complained about a missing sqlite3 gem. The sqlite3 gem wanted at least ruby-1.9.1 installed, so it was time to install another Ruby.

The ruby-1.9.1-p429 had a problem with gems, but a quick trip to Yahoo! revealed this message, so it was time to install another ruby!

rvm install ruby-1.9.1-p378
rvm use ruby-1.9.1-p378 --default
rvm gemset create rails238
rvm use ruby-1.9.1-p378@rails238 --default
gem install map_by_method what_methods awesome_print net-http-spy hirb looksee wirble sketches
gem install rails -v 2.3.8
gem install sqlite3

Now I can get to work playing with rails! The great thing is that I haven’t compromised my system Ruby, thanks to cider, rvm, and homebrew.

June 29th, 2010

Time to Learn Some More Tools

For a while now I have been put off programming by my daytime experiences, but a recent Ruby5 podcast has whetted my appetite for fun again.

The great thing I found was that the initial install didn’t quite go smoothly…

[Tue, 29 Jun 2010 07:42:01 -0400] INFO: Starting Chef Solo Run
[Tue, 29 Jun 2010 07:42:11 -0400] INFO: Replacing the run_list with ["homebrew", "homebrew::dbs", "homebrew::misc", "ruby", "ruby::irbrc", "ruby::rails", "ruby::sinatra", "node"] from JSON
[Tue, 29 Jun 2010 07:42:12 -0400] INFO: Setting group to 20 for template[/Users/mike/.cider.profile]
[Tue, 29 Jun 2010 07:42:12 -0400] ERROR: template[/Users/mike/.cider.profile] (/Users/mike/.rvm/gems/ruby-1.8.7-p299/gems/chef-0.8.16/lib/chef/mixin/recipe_definition_dsl_core.rb line 59) had an error:
Operation not permitted - /Users/mike/.cider.profile
/Users/mike/.rvm/gems/ruby-1.8.7-p299/gems/chef-0.8.16/bin/../lib/chef/provider/file.rb:118:in `chown'

… so now I have a chance to use rdebug on a real issue, and maybe get to learn something about OS X and the Ruby setup. I’m looking forward to learning more about Cider, and maybe having some fun again.

After a little fooling around with rdebug I decided that the most expedient thing to do was add myself to group 20 and see if Cider would install OK. A quick Yahoo search for adding a user to a group in OS X Snow Leopard led me to this post, and with a quick

dseditgroup -o edit -u mike -p -a mike -t user staff

The install seems to be progressing…

1 July 2010:

My goal was to leave the Snow Leopard install of Ruby alone, and see if I could get the entire thing set up without using sudo. Unfortunately that meant I had to install rvm (from tarball as OS X doesn’t have a git by default) and an rvm ruby to get going. When it tried to install the ~/Developer/… rvm it fell over.

So… use sudo to get cider installed as part of the OS X install and see what it does!

2 July 2010:

It looks like it’s more than just my Ruby which will get dusted off soon, Cider uses RVM which allows multiple rubies and gemsets, and Homebrew to manage installed software on OS X. I ought to know at least what all the programs and gems installed by Cider are, and maybe learn a few of them:

ratdog:~ mike$ brew list
ack		libevent	node		redis		wget
ctags		markdown	npm		rlwrap
fortune		memcached	postgresql	rpg
git		mongodb		proctools	sqlite
kiwi		mysql		readline	tig
ratdog:~ mike$ rvm list

rvm rubies

=> ruby-1.8.7-p248 [ x86_64 ]
ratdog:~ mike$ gem list

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.0.beta3, 2.3.8)
actionpack (3.0.0.beta3, 2.3.8)
activemodel (3.0.0.beta3)
activerecord (3.0.0.beta3, 2.3.8)
activeresource (3.0.0.beta3, 2.3.8)
activesupport (3.0.0.beta3, 2.3.8)
arel (0.3.3)
awesome_print (0.2.1)
builder (2.1.2)
bundler (0.9.26)
configuration (1.1.0)
engineyard (0.3.2)
erubis (2.6.6)
escape (0.0.4)
heroku (1.9.9)
highline (1.5.2)
hirb (0.3.2)
i18n (0.3.7)
json (1.4.3)
json_pure (1.4.3)
launchy (0.3.5)
looksee (0.2.1)
mail (2.2.5)
map_by_method (0.8.3)
memcache-client (1.8.3)
mime-types (1.16)
net-http-spy (0.2.1)
polyglot (0.3.1)
rack (1.1.0)
rack-mount (0.6.6)
rack-test (0.5.4)
rails (3.0.0.beta3, 2.3.8)
railties (3.0.0.beta3)
rake (0.8.7)
rdoc (2.5.8)
rest-client (1.5.1, 1.4.2)
sinatra (1.0)
sketches (0.1.1)
termios (0.9.4)
text-format (1.0.0)
text-hyphen (1.0.0)
thor (0.13.7)
treetop (1.4.8)
tzinfo (0.3.22)
what_methods (1.0.1)
wirble (0.1.3)
March 19th, 2009

Toronto Ruby user group lives again

Last night we had the first meeting of the Toronto Ruby User Group’s third incarnation. Thanks to Kent Fenwick for taking over the organisation and getting us a space at the University of Toronto.

If you’re interested in Ruby in the Toronto area then http://www.meetup.com/toronto-ruby-meetup/ is the place to look.