background preloader

Ruby

Facebook Twitter

Rubular: a Ruby regular expression editor and tester. Ruby Quiz - metakoans.rb (#67) Metakoans.rb (#67) by ara.t.howard [ Editors note: This quiz file can be downloaded: metakoans.rb Partial solutions are welcome. --JEG2 ] ruby module MetaKoans def koan_1 c = Class::new { attribute 'a' o = c::new assert{ not o.a?

Assert{ o.a = 42 } assert{ o.a == 42 } assert{ o.a? End def koan_2 class << self assert{ not c.a? Assert{ c.a = 42 } assert{ c.a == 42 } assert{ c.a? Def koan_3 m = Module::new { assert{ not m.a? Assert{ m.a = 42 } assert{ m.a == 42 } assert{ m.a? Def koan_4 include m extend m def koan_5 o = Object::new class << o def koan_6 attribute 'a' => 42 assert{ (o.a = nil ) == nil } def koan_7 attribute( 'a' ){ fortytwo } def fortytwo def koan_8 b = Class::new { attribute( 'b' ){ a } c = Class::new b assert{ (c.a = nil ) == nil } def koan_9 include Module::new { assert{ c.a = 'forty-two' } assert{ c.a == 'forty-two' } assert{ b.a == 42 } def assert() bool = yield class MetaStudent def initialize knowledge require knowledge def ponder koan begin send koan true rescue => e false class MetaGuru require "singleton" if awakened.

Mike Clark › Ruby Learning Test #1: Are You There, World? I truly have no idea where this is going or if it will scale.

Mike Clark › Ruby Learning Test #1: Are You There, World?

But I've been meaning to try it, and I'll let you judge whether it's worth it. Here's what I do know: It doesn't cost you anything to come along for the ride. How I Learned Ruby A couple years back I flipped open the first edition of Dave and Andy's wonderful book Programming Ruby. A few pages in I'm introduced to my first Ruby code. But it was at that very moment when I asked Ruby a question and it responded with the answer that I learned more than Ruby.

There was just one problem: I didn't yet know enough about Ruby to write a test. [~/work/code/ruby/learn] $ ruby all_learning_tests.rb ruby all_learning_tests.rbLoaded suite all_learning_testsStarted.......................... That's pretty much everything I know about Ruby, give or take. But the real value of writing these tests was less about testing, and more about learning. So You Want To Learn Ruby?

One caution before we go any further: Ruby has spoiled many programmers. Index of Classes & Methods in Ruby 1.9.3. Ruby Programming Language.