Skip to content

Instantly share code, notes, and snippets.

View ysulaiman's full-sized avatar

Yaser Sulaiman ysulaiman

View GitHub Profile
@ysulaiman
ysulaiman / array_to_hash.rb
Last active December 10, 2015 15:19
How to convert an Array to a Hash using the new form of the `Hash#[]` method available in Ruby 1.9.2 and above. The example is from Slide #28 of the Functional Programming with Ruby presentation by Arnau Sanchez (http://www.slideshare.net/tokland/functional-programming-with-ruby-9975242).
values = %w[ ride the dragon ]
lengths = Hash[values.map { |e| [e, e.length] }]
#=> {"ride"=>4, "the"=>3, "dragon"=>6}
@ysulaiman
ysulaiman / _test.rb
Created November 25, 2012 18:48 — forked from jcoglan/_test.rb
$VERBOSE = nil
require File.expand_path('../rooby', __FILE__)
Person = Rooby::Class.new 'Person' do
define :initialize do |name|
@name = name
end
define :name do
@ysulaiman
ysulaiman / ruby_quiz_234.rb
Created June 21, 2010 21:47
A solution for Ruby quiz #234 - Random Points within a Circle
# A solution for Ruby quiz #234 - Random Points within a Circle.
# http://rubyquiz.strd6.com/quizzes/234-random-points-within-a-circle
# Yaser Sulaiman.
class Point
attr_accessor :x, :y
def initialize(x = 0, y = 0)
@x, @y = x, y
end