Stok Footage

Continually experimenting with new ideas and techniques — Reconstructing, Developing, Modernising.

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

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *