I was meta-meta-programming, and had an issue when an #included method was called:


1 anon = Module.new
2 anon.class_eval do
3 def self.included(base)
4 debugger
5 if some_method then
6 # code
7 else
8 # more code
9 end
10 end
11 end

The code above resulted in:


1 /Users/francois/Projects/project/lib/extensions.rb:214:in `included’: undefined local variable or method `some_method for #<Module:0×103305b20> (NameError)
2 from /Users/francois/Projects/project/lib/extensions.rb:245:in `include

3 from /Users/francois/Projects/project/lib/extensions.rb:245:in `send’
4
5

The debugger statement above just wouldn’t take: Ruby ran right over it. I happened to look at ruby-debug’s Rubygem spec file:


1 - !ruby/object:Gem::Specification
2 name: ruby-debug
3
4 executables:
5 – rdebug
6

Oh, had never noticed the executables before… Sure enough, I managed to run under debugger control immediately:


1 $ rdebug -I test test/functional/ad_spots_controller_test.rb [-4, 5] in /Users/francois/Projects/bloom/adgear-admin/test/functional/ad_spots_controller_test.rb
2 => 1 require "test_helper"
3 2
4 3 class AdSpotsControllerTest < ActionController::TestCase
5 4
6 5 def setup
7 /Users/francois/Projects/bloom/adgear-admin/test/functional/ad_spots_controller_test.rb:1
8 require "test_helper"
9 (rdb:1)

From there, I was able to use (C)ontinue to end up on my debugger statement. Happy times ensued!

For the curious, the NoMethodError is because #some_method is defined on base, not on self. self in this context is the included module, while base is the place where we’re including it into.

I just stumbled upon Is Windows a First Class Platform for Ruby? by Peter Cooper and Is Windows a supported platform for Ruby? I guess not by Luis Lavena.

I have to admit, I did use Windows daily for 3 years before I switched permanently to Ubuntu, about 6 months back. Initially, I was using IntelliJ’s IDEA as my development platform, then I switched to the e Text Editor. I never had many problems with gems that didn’t/couldn’t/wouldn’t install. There are many kind souls in the community that keep these gems up to date. I’m talking specifically about Tim Hunter (RMagick), Luis Lavena (Mongrel) and others.

Just before I made the final switch, I was using Linux in a VMware image to run XLsuite. The application was unbearably slow in Windows, but acceptable in a virtual machine. I was using the e Text Editor as my editor, accessing the code through a Samba share.

My own experience was pretty positive. Now that I’m on Ubuntu, I wouldn’t go back though. What made me switch ? Better performance on the same hardware, mostly; the novelty of the experience. I do not dislike Windows, nor do I think Redmond is a bad place. Windows is a fine platform.

Just to contrast, look at the excellent support Java enjoys on Windows. Windows is the 2nd platform for Java (with Solaris being the 1st). We, the Ruby community, should be learning from Sun. There are many, many more Windows machines than Mac or Linux machines out there. There are literally millions of people who could learn to write Ruby, but are on Windows. Dr Nic said it all: … People Use Windows Too. Whether you want to or not, Windows isn’t going away soon.

Personally, I have made the switch. But just on my small team, Windows users outnumber other platforms 1 to 1. Here’s the breakdown:

  • 4 Windows (2 coders, 1 designer, 1 sponsor)
  • 2 Ubuntu (1 coder, 1 designer)
  • 1 Mac (1 ExtJS coder)

Is Windows a good platform for Ruby ? Yes. Is Windows a great platform for Ruby ? No, but there’s no reason why it shouldn’t be. Just look at Why‘s work on Hackety Hack. I’m really impressed and happy that I will be able to show Ruby to my daughters. The catch ? Hackety Hack is for Windows only right now.

Please, let’s keep and increase Windows support. Once they’re hooked, they might switch, who knows ?

Gregory Brown, of Ruby Reports and PDF::Writer fame, wants to quit his job, sort of.

Here’s a crazy idea I just had, and I’m wondering what folks think about it.

People do open source for a lot of reasons, ranging from pragmatic to idealistic. …

What if I could just do open source for a while, non-commercially?

How much would it cost for me to do at least 80 hours a month of development on software projects such as PDF::Writer, Ruport, and some other projects I wish I had the time to get my hands on?

I did the math, and the number came out low (subjective). I could meet all my expenses and save some money for about $2000 a month. Basically, if 200 people donated $60 right now, I could take 6 months off and do nearly 500 hours of work, and that’s only if I didn’t find myself obsessed with and doing extra hours on a project.

Gregory Brown, in I’d love to quit my job!

Gregory started a Wiki where he documented his proposal. Head on over to the Ruby Mendicant for the details.

Finally, if you’d like to donate (like I did !), head on over to pledgie:

Click here to lend your support to: Ruby Mendicant and make a donation at www.pledgie.com !

I have a passing interest in Git. I haven’t migrated my projects over to it now, but am looking into it. Just for fun, I googled “ruby git”, and I found Ruby/Git. I thought more people should know about this.

I was writing a test for a method named hit! and I wrote the following:


1 def test_calling_hit!_increments_hit_count
2 # …
3 end

Running the tests didn’t pick this up. I renamed the method to:


1 def test_calling_hit_bang_increments_hit_count
2 # …
3 end

And that obviously worked. So, Ruby accepts ! and ? as suffixes, but not anywhere else. Of course, using Shoulda I wouldn’t have had the problem, since I would have written:


1 context "Calling #hit!" do
2 should "increment the hit counter by one" do
3 # …
4 end
5 end

Notice the bang is within a String, so no problem there.

I really like Smalltalk’s ifNil: and ifNotNil:, and up to now, I could not use these in Ruby. Fortunately, Bob Hutchison came to the rescue with A Little Unnecessary Smalltalk Envy.

I immediately copied that to XLsuite and wrote a couple of tests. Here is sample of what the code feels like:


1 >> Party.find_by_email_address("sam@gamgee.net").if_not_nil do |party|
2 ?> puts "Found Sam!"
3 >> end
4 => nil

Oh well, no Sam in my database. The code is here:

test/unit/smalltalk_test.rb

1 require File.dirname(FILE) + "/../test_helper"
2
3 class SmalltalkTest < Test::Unit::TestCase
4 setup do
5 block</span> = <span class="co">Proc</span>.new { <span class="pc">true</span> } <span class="no"> 6</span> <span class="r">end</span> <span class="no"> 7</span> <span class="no"> 8</span> context <span class="s"><span class="dl">&quot;</span><span class="k">The nil object</span><span class="dl">&quot;</span></span> <span class="r">do</span> <span class="no"> 9</span> should <span class="s"><span class="dl">&quot;</span><span class="k">yield when calling #if_nil on it</span><span class="dl">&quot;</span></span> <span class="r">do</span> <span class="no"><strong>10</strong></span> assert <span class="pc">nil</span>.if_nil(&amp;<span class="iv">block)
11 end
12
13 should "not yield when calling #if_not_nil on it" do
14 deny nil.if_not_nil(&block</span>) <span class="no"><strong>15</strong></span> <span class="r">end</span> <span class="no">16</span> <span class="r">end</span> <span class="no">17</span> <span class="no">18</span> context <span class="s"><span class="dl">&quot;</span><span class="k">A non nil object</span><span class="dl">&quot;</span></span> <span class="r">do</span> <span class="no">19</span> should <span class="s"><span class="dl">&quot;</span><span class="k">not yield when calling #if_nil on it</span><span class="dl">&quot;</span></span> <span class="r">do</span> <span class="no"><strong>20</strong></span> deny <span class="s"><span class="dl">&quot;</span><span class="dl">&quot;</span></span>.if_nil(&amp;<span class="iv">block)
21 end
22
23 should "yield when calling #if_not_nil on it" do
24 assert "".if_not_nil(&@block)
25 end
26
27 should "pass itself to #if_not_nil" do
28 obj = "abc"
29 assert_same obj, obj.if_not_nil {|o| o}
30 end
31 end
32 end

lib/smalltalk.rb

1 # Copied and adapted from
2 # http://recursive.ca/hutch/2007/11/22/a-little-unnecessary-smalltalk-envy/
3 # Bob Huntchison
4 class Object
5 # yield self when it is non nil.
6 def if_not_nil(&block)
7 yield(self) if block
8 end
9
10 # yield to the block if self is nil
11 def if_nil(&block)
12 end
13 end
14
15 class NilClass
16 # yield self when it is non nil.
17 def if_not_nil(&block)
18 end
19
20 # yield to the block if self is nil
21 def if_nil(&block)
22 yield if block
23 end
24 end

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on