num = (1..100).each
fizz = ([""] * 2 + ["Fizz"]).cycle
buzz = ([""] * 4 + ["Buzz"]).cycle
loop do
n = num.next
puts (fizz.next + buzz.next).sub(/\A\z/) { n }
end
FizzBuzz with Sather like loop
Posted by: Shugo Maeda Fri, 24 Aug 2007 23:06:00 GMT
Sather like loop
Posted by: Shugo Maeda Fri, 24 Aug 2007 13:15:00 GMT
Sather like loop is available in the SVN head.
e1 = [1,2,3,4,5].each
e2 = ["a","b","c","d","e"].each
loop do
p [e1.next, e2.next]
end
It's cool, isn't it?
Building MySQL/Ruby on mswin32
Posted by: Shugo Maeda Sun, 24 Sep 2006 21:30:00 GMT
I created a patch to build MySQL/Ruby on mswin32. With this patch, just type:
> ruby extconf.rb --with-opt-include=../mysql-4.1.21-win32/include \
--with-opt-lib=../mysql-4.1.21-win32/lib/opt
> nmake
Then you'll get mysql.so. Really easy.
If libmysql.dll is built by VC7 or later, there may be a problem with GC. It depends on whether MySQL/Ruby releases memory allocated by libmysql.dll using free()/xfree() or not.
RubyKaigi is Sold Out!
Posted by: Shugo Maeda Wed, 10 May 2006 21:35:00 GMT
Tickets of RubyKaigi are sold out in a few hours!
I'll talk about meta programming features of Ruby. See you in Tokyo.
Rails on YARV
Posted by: Shugo Maeda Tue, 21 Feb 2006 06:23:00 GMT
A history of continuation
Posted by: Shugo Maeda Mon, 17 Oct 2005 05:53:00 GMT
I attended Jim Weirich and Chad Fowler's tutorial on RubyConf today. It was about continuation and quite a interesting one. I learned many about The Legend of Zelda:) Thanks, Jim and Chad.
Someone asked a question, "Is it similar to goto?" Then I remember
why continuation was added to Ruby.
In 1998, someone requested goto to Matz. Matz said that he doesn't
want to add goto to Ruby because it's difficult to implement and there is
no benefit to do it. So I asked him, "How about continuation?" He said,
"Continuation may be acceptable."
Then, I implemented it using thread implementation. The first implementaion was just a 94 lines patch. Certainly it was an incomplete implementaion, but it was very easy to implement thanks to thread. That patch was merged to Ruby finally.
Continuation may be harmful especially for languages that allow many side effects such as Ruby. Maybe it should be removed from Ruby 2.0. I have not used continuation in real applications, so I can do without it.
But it's a very interesting feature, and I want see it in Ruby 2.0. How about others?
Looking for a Rails developer in Tokyo
Posted by: Shugo Maeda Fri, 16 Sep 2005 16:36:00 GMT
JRCgroup is looking for a Rails developer in Tokyo.
Qualifications are:
- Engineering or programming background.
- Ruby knowledge.
- Finance/Real estate background would be appreciated but not required.
- Intermediate level Japanese (if native English speaker)
- Intermediate level English (if native Japanese speaker)
For more information, please contact shugo@ruby-lang.org.
Why jcode.rb?
Posted by: Shugo Maeda Fri, 16 Sep 2005 14:59:00 GMT
I'm wondering why so many people use jcode.rb on Rails. jcode.rb may break other libraries because it redefines some methods of String. So I recommend you not to use jcode.rb if it is not really necessary.
In many cases, you can use Regexp instead. For example,
require "jcode"
$KCODE = "u"
s.each_char do |ch|
puts ch
end
This code can be rewritten like this:
s.scan(/./mu) do |ch|
puts ch
end
I admit that the latter is less readable than the former. M17N features or selector namespace will fix this problem completely in the near future, I hope.