- For the purpose of maintaing compatibility between Ruby 1.8 and Ruby 1.9, "Ruby Best Practices" suggests better ways as follows.
- write codo against Ruby 1.9 first and then backport to 1.8
- In order to avoid writing too much legacy code, we seem to have to write code supporting the later version first. It cannot apply to my project because BioRuby has already support the earlier version.
- attempt to find a way to write code that runs natively n both Ruby 1.8 and 1.9
- Avoid implementing redundant code or modifying core Ruby code as much as possible
- consider backporting the necessary functionality to Ruby 1.8
- If a method used in the library is different between Ruby 1.8 and 1.9, you should create new methods in classes of one version for the compatibility.
- Introduce a helper method that behaves the same on both versions
- For example, you may add Enumerator to String of Ruby 1.8. That provide the same behavior as "lines" method of Ruby 1.9
- use brocks for the version checking
- Don't use a conditional statement. Use the following code
def hoge(bar)
this way centralizes incompatibility.
ruby_18 {...} || ruby_19 {...}
end
reference: Brown G. Ruby Best Practices. O'Reilly Media, Inc. 239-249; 2009.
No comments:
Post a Comment