Using 'return' in a Ruby block

I’m trying to use Ruby 1.9.1 for an embedded scripting language, so that “end-user” code gets written in a Ruby block. One issue with this is that I’d like the users to be able to use the ‘return‘ keyword in the blocks, so they don’t need to worry about implicit return values. With this in […]

How to get a random number in Ruby

How do I generate a random number between 0 and n?

“193: %1 is not a valid Win32 application” bug with a new Rails Application

I have a new rails application which I have created under Windows 7 by going into a directory and typing “rails newapp”. The creation went fine, and when I access the root page, all is well. However, when I try to access a page that would access the database, I get this: 193: %1 is […]

Regex to match Date

I want to match dates with format mm/dd/yy or mm/dd/yyyy but it should not pick 23/09/2010 where month is 23 which is invalid nor some invalid date like 00/12/2020 or 12/00/2011.

Updating jekyll using gem

I wanted to try out jekyll on Windows. But unfortunately the machine I was trying did not gave me installation rights. So I decided to go with portable jekyll. I put that repo in my D:\Program Files\jekyll folder. Updated the PATH in System Environment Variables. However this jekyll setup has older gems for sass, jekyll. […]

How do I pick randomly from an array?

I want to know if there is a much cleaner way of doing this. Basically, I want to pick a random element from an array of variable length. Normally, I would do it like this: myArray = [“stuff”, “widget”, “ruby”, “goodies”, “java”, “emerald”, “etc” ] item = myArray[rand(myarray.length)] Is there something that is more readable […]

Rake Command Not Working

Getting this error while running RAKE command :- rake –trace rake aborted! There was an error while trying to load the gem ‘coffee-rails’. /usr/local/rvm/gems/ruby-1.9.3-p194/gems/bundler-1.11.2/lib/bundler/runtime.rb:81:in rescue in block (2 levels) in require’ /usr/local/rvm/gems/ruby-1.9.3-p194/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require’ /usr/local/rvm/gems/ruby-1.9.3-p194/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each’ /usr/local/rvm/gems/ruby-1.9.3-p194/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require’ /usr/local/rvm/gems/ruby-1.9.3-p194/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each’ /usr/local/rvm/gems/ruby-1.9.3-p194/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require’ /usr/local/rvm/gems/ruby-1.9.3-p194/gems/bundler-1.11.2/lib/bundler.rb:99:in `require’ /apps/apache/Sekhmet/user/config/application.rb:7:in `<top (required)>’ /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require’ /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in […]

How to update ruby gem re-readline 5.0 to rb-readline 5.1

I am working on ruby on rails and I want to update gem rb-readline 5.0 to rb-readline 5.1 . I am new in this field and want to know how to update this single gem step by step .Kindly help.

How to modify PATH for Homebrew?

Trying to install ruby 1.9.3, read that I need to install homebrew first. Ran brew doctor, and it’s giving me a bunch of warnings. One of which is: Warning: /usr/bin occurs before /usr/local/bin This means that system-provided programs will be used instead of those provided by Homebrew. The following tools exist at both paths: easy_install […]

How to split (chunk) a Ruby array into parts of X elements?

I have an array foo = %w(1 2 3 4 5 6 7 8 9 10) How can I split or “chunk” this into smaller arrays? class Array def chunk(size) # return array of arrays end end foo.chunk(3) # => [[1,2,3],[4,5,6],[7,8,9],[10]]

Ruby is the best programming language in the world - Ruby on Rails.