ihower speaks English RSS

Follow ihower on Twitter

I'm Wen-Tien Chang (a.k.a. ihower). I work on Ruby and Ruby on Rails professionally. Besides, I run Ruby Taiwan community and RubyConf Taiwan.

Here is my english blog. My chinese blog is at http://ihower.tw

ihower {at} GMail.com

Archive

Jul
18th
Mon
permalink

BDD style unit testing video and slides@RubyKaigi 2011

This is my slides and video recording at RubyKaigi 2011 (with speaker’s note every page). It’s my first English presentation and the time is 30mins, so I only talk about the core value of BDD, basic BDD style syntax, why the syntax matters and some BDD caveats you should know and think.

I’m such nervous and may speak too quickly (only use 25 mins). I asked all attendees and found surprisingly more than half attendees do unit testing and RSpec, which means most attendees already knows unit testing and RSpec. Great! Now I’m afraid of my talk will be too easy :P Anyway, hope this talk can help you realize why we do BDD unit testing and not only because RSpec’s awesome syntax.

BTW, If you’re interested in more RSpec syntax, you can checkout my RSpec talk at OSDC.TW.

Sep
21st
Tue
permalink

My Mac Development Installation Guide (Rails3)

Textmate bundle:

Software:

Dashboard:

  • PEMDAS
  • CurrencyConverter

More Mac software at http://ihower.tw/blog/archives/4318

Mar
18th
Thu
permalink

Rails3: ActiveSupport::Concern

(Chinese version)

ActiveSupport::Concern is an important tool for Rails3 modularity. It makes managing module dependencies management very easy and intuitional.

Suppose we have two modules which have dependency relationship. Module Bar depends on module Foo. And there is a class Host which intends to include Bar features. Therefore we can write code like this:

module Foo
   # self.included will be executed when Foo is included
    def self.included(base)
        # Do some enhancements for Host class
        base.send(:do_host_something)
    end
end

module Bar
    def self.included(base)
        base.send(:do_host_something)
    end
end

class Host
    include Foo, Bar
end

But there is a hateful disadvantage: we have to include both Foo and Bar inside Host class. It means we have to include all dependent modules. That’s bad! Why should we need to know modules dependency inside Host class? :/

We wish that we can write dependency relationship in modules instead of Host class, so we can just include the module which we want to use it inside Host class. For this reason, we rewrite it to:

module Bar
include Foo # We include Foo here because Bar depends on Foo

    def self.included(base)
         base.send(:do_host_something)
    end

end

class Host
    include Bar # Only need to include Bar. Need not to know Bar's dependency
end

It looks fine, but there is a fatal error which prevents it running. The reason is that we include Foo in Bar module now, so when we are inside Foo’s self.included method, its base parameter becomes Bar module (not Host class anymore). So it can not access any methods and variables in Host class. It fails when do_host_something.

Okay,ActiveSupport::Concern is the antidote. We wish Host class need not to know module dependencies. The dependencies are written in module.

require 'active_support/concern'

module Foo
    extend ActiveSupport::Concern
    included do
        self.send(:do_host_something)
    end
end

module Bar
    extend ActiveSupport::Concern
    include Foo # We include Foo here because Bar depends on Foo

    included do
        self.send(:do_host_something)
    end
end

class Host
    include Bar # Only need to include Bar. Need not to know Bar's dependency
end

It’s done. One more thing: If you define module ClassMethods and module InstanceMethods, it will automatically load to Host class. So you need not to write send(:include, InstanceMethods) and send(:extend, ClassMethods). For example:

module Foo
    extend ActiveSupport::Concern
    included do
        self.send(:do_host_something)
    end

    module ClassMethods
        def bite
         # do something
        end
    end

    module InstanceMethods
        def poke
        # do something
        end
    end
end

If you want to know what exactly ActiveSupport::Concern doing, please checkout /activesupport/lib/active_support/concern.rb. Only 29 lines, and it does not depend any other library. It’s awesome!

Jan
29th
Fri
permalink

First Post

I have no idea why there are 4 followers here before I write anything? Anyway, I will begin to write something in English at tumblr, mostly because I want to practice my English writing skill.

Few weeks ago, I asked my good friend, Roy, who is a professional English teacher (One proverb says “Go away! Let professional handle!”). Could he help me speak English well? I’m confident in my reading ability (at least for computer technical articles), but I have trouble communicating with native English people directly. One reason is that I listen too seldom, and another reason I think is because my English pronunciation is bad.

For example, I can not distinguish “beat”, “bit”, “bait”, “bet”, “bat”, “baht”, “bought”, “boat”, “book”, “boot”, “but”, “burn” well. There are many times that I said some words, but the listener can not understand what I’m talking about. It’s so embarrassed.

Today is our first lesson, my textbook is “Improve Your American English Accent”. We will process session by session every week. My teacher also recommends me listening ESL podcast everyday, which is more suitable for me now.

I swore many times to practice English every single day. Hope this time, I will last longer :)