Rails ActiveSupport provides a few methods which make changing between constants and keys really easy. Let’s look at #underscore and #camelize extending string. These methods are very useful when passing around Constants which need to be flipped into methods or attribute keys and values. class MastersCriteria end   class College attr_accessor :curriculum   def initialize(curriculum) @curriculum = curriculum end   end   >> College.new(:curriculum => "#{MastersCriteria}".underscore) => #<College:0x007ffd96377d28 @curriculum={:curriculum=>"masters_criteria"}> Camelize then helps us grab the string and turn it back into a constant we can use once again. Here is the source for underscore already written we saved time by using #underscore class String def underscore self.gsub(/::/, ‘/’). gsub(/([A-Z]+)([A-Z][a-z])/,’\1_\2’). gsub(/([a-z\d])([A-Z])/,’\1_\2’). tr("-", "_"). downcase end end :)

Today’s tip is a basic construct of Ruby. After declaring a variable (creating an object) that object becomes the receiver for new methods, but the class of that object will not inherit those methods. fish_tacos = "fish"   def fish_tacos.toppings puts "red cabbage" end   fish_tacos.toppings #=> "red cabbage"   "chicken".toppings NoMethodError: undefined method `toppings’ for "chicken":String from (irb):1 from /Users/brettu/.rvm/gems/ruby-1.9.3-p0@mgk/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start’ from /Users/brettu/.rvm/gems/ruby-1.9.3-p0@mgk/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start’ from /Users/brettu/.rvm/gems/ruby-1.9.3-p0@mgk/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>’ from script/rails:6:in `require’ from script/rails:6:in `<main>’ The String object itself won’t know about the .toppings() method only the fish_toppings instance of String. :)