顯示具有 Ruby 標籤的文章。 顯示所有文章
顯示具有 Ruby 標籤的文章。 顯示所有文章

2009年6月7日 星期日

[Ruby] 在Ruby程式使用單複數轉換

取用Rails中內含的Module - ActiveSupport

Module:
ActiveSupport::Inflector
ActiveSupport::Inflector::Inflections


如果你有裝 rails 那裡面就包含了ActiveSuppt,如果沒有的話可以透過以下指令來安裝:

C:\> gem install rails

或是只裝Active Support
C:\> gem install activesupport


Sample Code:
require 'active_support/inflector'
require 'active_support/inflections'

puts "box".pluralize # => "boxes"
puts "child".pluralize # => "children"

puts "pets".singularize # => "pets"
puts "women".singularize # => "woman"


It's so cool!!

2009年5月28日 星期四

[RoR] 相關資源網站整理


Ruby is…

A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.

Ruby Programming Language
http://www.ruby-lang.org

Try Ruby! in your browser
http://tryruby.hobix.com/

Ruby-Doc
- Help and documentation for the Ruby programming language.
http://www.ruby-doc.org/

RDoc
- Documentation from Ruby Source Files
http://rdoc.sourceforge.net/

Ruby-Forum
http://www.ruby-forum.com/

RubyForge is a home for open source Ruby projects
https://rubyforge.org/

Rubular - a Ruby regular expression editor
http://www.rubular.com/

RMagick - Graphics Processing for Ruby and Ruby on Rails
http://rmagick.rubyforge.org/

REXML: Processing XML in Ruby
http://www.xml.com/pub/a/2005/11/09/rexml-processing-xml-in-ruby.html

JSON implementation for Ruby
http://json.rubyforge.org/

MySQL API Module for Ruby
http://www.tmtm.org/en/mysql/ruby/

Ruby on Rails
http://rubyonrails.org/

Rails Framework Documentation
http://api.rubyonrails.org/

Railscasts - Free Ruby on Rails Screencasts
http://railscasts.com/

Crossing borders: Ajax on Rails
http://www.ibm.com/developerworks/java/library/j-cb12056/?S_TACT=105AGX52&S_CMP=cn-a-j

2009年5月27日 星期三

[Ruby]用Tk與Open-uri在視窗上顯示圖片

執行結果:



=begin
用Tk建立視窗並用open-uri由網頁讀入圖片
Last Update: 2009/05/27
=end
require 'tk'
require 'tkextlib/tkimg/jpeg'
require 'open-uri'

# => 圖片路徑
imgPath = "http://img38.imageshack.us/img38/9177/xr053.jpg"
photo = open(imgPath, "rb") {|io| io.read}

TkRoot.new {title "Sunflower" } # => 標題列文字

# => 建立一個Label 放置圖片
TkLabel.new {
image TkPhotoImage.new(:data => Tk::BinaryString( photo ) )
#width 680
pack
}

# => 新增一個Label 填入文字
TkLabel.new {
font TkFont.new( 'verdana 24 bold' )
text "Shining Sunflower"
pack
}

# => 建立一個離開Quit按鈕
TkButton.new {
text 'Quit'
command 'exit'
pack
}

Tk.mainloop

2009年5月25日 星期一

[Ruby] 在Ruby使用Tk

雖然Ruby有內建Tk,不過在Windows用好像有點問題。

執行時出現
c:/ruby/lib/ruby/1.8/i386-mswin32/tcltklib.so: 126: 找不到指定的模組。缺少TK84.dll

解決方法:

Step1: 安裝 ActiveTcl
我是用ruby 1.8.6(C:\ruby -v)
他跟我要的是TK84.dll,所以我抓了ActiveTcl8.4.19.1
如果裝ActiveTcl are 8.5.7.0就變TK85.dll了。

Step2: 裝好之後就可以測試在Ruby使用Tk的程式了,一切正常。

require 'tk'
TkRoot.new {title "Ruby is fun!"}

TkLabel.new {
    font TkFont.new( 'mistral 42')
    text "Hello, I am Hank. Have a nice day."
    width 30
    fg 'blue'
    pack
}

TkButton.new {
    text 'Quit'
    command 'exit'
    pack
}

Tk.mainloop


Related Posts Plugin for WordPress, Blogger...