Archive for the ‘ruby’ Category

Ruby Strftime Day Without the Leading Zero

Posted 20 Feb 2010 — by admin
Category ruby
%e # rather than %d
Time.now.strftime("%e")

Hello Rack

Posted 15 Dec 2009 — by admin
Category ruby

What is Rack?

Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.

- Rack API Docs


Create and name your file config.ru If rack isn’t installed get it with this command

gem install rack

In your config.ru file

require 'rubygems'
require 'rack'

class HelloRack
  def call(env)
    [200, {"Content-Type" => "text/html"}, "Hello Rack!"]
  end
end

Rack::Handler::Mongrel.run HelloRack.new, :P ort => 8888

Check out http://m.onkey.org/2008/11/17/ruby-on-rack-1

Reading, Writing, Removing Files and Directories in Ruby

Posted 30 Nov 2009 — by admin
Category ruby

These aren’t all of them, but I think they are some of the most useful.

# making a directory in another directory that doesn't yet exist...
FileUtils.mkdir_p '/path/to/your/directory/that/doesnt/exist/yet'

# recursively remove a directory and the contents
FileUtils.rm_rf("/path/to/directory/you/want/to/delete")

# write a file from the contents of another file...
File.open("/path/to/the/file.ext", "wb") {|f| f.write(@your_other_file.read)}

How to Install a Ruby Package without Ri or RDoc

Posted 13 Nov 2009 — by admin
Category ruby
gem install --no-rdoc --no-ri rails