Archive for the ‘Ruby’

Something in Ruby05.30.08

#!/usr/bin/env ruby

String.class_eval {
  define_method(:translate_to) do |lang|
    text = case lang
           when :spanish 
           "Buenos Dias, Como estas hoy?"
           when :english
           "Good Morning, How are you today?"
           else
           "I don't speak any other language."
           end
  end
}

puts "Sentence".translate_to :spanish
# => Prints out "Buenos Dias, Como estas hoy?"

puts "Sentence".translate_to :english
# => Prints out "Good Morning, How are you today?"

puts "Setenece".translate_to :portuguese
# => Prints out "I don't speak any other language."

puts "Sentence"
# => Prints out "Sentence"

So while messing round I made this in Ruby… I’m not sure if it is considered meta programming? Well, it’s just adding a method to the String class. I get confused when to consider things to be meta programming.. Maybe I over think about it.

Posted in Programming, Rubywith 1 Comment →

Heroku Invites05.25.08

Ruby On Rails Heroku Beta Invites

So I received an invite for heroku a while ago. I never really used it. Want an invite to check out heroku.com? I have many invites to give away. Want one? just leave your email and I will send you one your way!

Posted in Ruby, Ruby On Railswith 11 Comments →

Rails on Dreamhost05.21.08

Dreamhost now supports mod_rails Passanger.

Posted in Ruby, Ruby On Railswith Comments Off on Rails on Dreamhost

Passenger – mod_rails for Apache04.11.08

So even if you have never set-upped a Rails Application to Production server there is still hope for you. Introducing Passenger a mod_rails for Apache… Make it super simple to deploy apps just like PHP. Check it out over at modrails.com 

Posted in Ruby, Ruby On Railswith 2 Comments →

Ruby Technique: Meta Programming03.02.08

Meta Programming is code that writes code. See the code sample below.
I have made a screencast of this process. View it here

#!/usr/bin/env ruby

class Product
  def initialize(items)
    items.each {|item| Product.product(item) }
  end

  def self.product(item)
    code = %Q{
      def add_#{item}(item)
        @#{item} = [] unless @#{item}
        @#{item} << item
      end

      def display_#{item}s
        @#{item}.each {|item| puts item }
      end
    }
    class_eval(code)
  end
end

class Item < Product
  def initialize(*items)
    super(items)
  end
end

cart = Item.new(:book, :computer, :music)
cart.add_book(:Ruby) # => Add a book to our cart items

cart.display_books # => We want to display All books we have added
puts "\n"

cart.add_computer(:Apple)
cart.add_computer(:Dell)
cart.add_computer(:Sony)
cart.display_computers # => Display All Computers
puts "\n"

cart.add_music(’Modest Mouse‘)
cart.add_music(’Northstar‘)
cart.display_musics # => Display All Music Items

Posted in Programming, Rubywith Comments Off on Ruby Technique: Meta Programming

Ruby Code Snippet01.13.08

In Ruby a switch statement looks like this

say = "Hello"

case say
when "Hello" then
	puts "Say Hello"
when "Bye" then
	puts "Say Bye"
end

In PHP a switch statement looks like this


Posted in Programming, Rubywith Comments Off on Ruby Code Snippet

Ruby MySpace Status Updater01.05.08

I have written a MySpace Status Updater class in Ruby. So if you want it take it, download it, use it.Download Here Or Download the RubyGem 

How do you use it?

credentials = {:username => ”, :password => ”, :status => %q(Okay Now I am really Done!…)}

@status = MySpace.update_status(credentials) 

Posted in Rubywith 2 Comments →

  • Recent Comments