def is_substr?(str1, str2)
re = Regexp.new(str1)
if re =~ str2
return true
else
return false
end
end
Filed under: Lập trình Ruby, Thư viện code | Leave a Comment »
def is_substr?(str1, str2)
re = Regexp.new(str1)
if re =~ str2
return true
else
return false
end
end
Filed under: Lập trình Ruby, Thư viện code | Leave a Comment »
Ruby forum: http://www.ruby-forum.com/ ; diễn đàn tốt, có thể đặt câu hỏi hoặc thảo luận
Ruby Programming Language: http://www.ruby-lang.org/en/ ; Có thể download phiên bản ruby mới nhất, cập nhật các thông tin về sự phát triển của ruby, tài liệu, etc
Ruby Reference: http://www.ruby-lang.org/en/
IDE tốt cho Ruby: Mặc dù khá nặng nhưng NetBean vẫn là IDE [...]
Filed under: Góc kỹ thuật và lập trình, Lập trình Ruby | Leave a Comment »
Dir.entries(ten_thu_muc).each { |file|
# Some process here
}
Filed under: Lập trình Ruby, Thư viện code | Leave a Comment »
Đầu vào: Câu đã được POS Tagging. Ví dụ
Upon_IN such_JJ reading_NN of_IN any_DT such_JJ certificate_NN or_CC paper_NN ,_, the_DT President_NNP of_IN the_DT Senate_NNP shall_MD call_VB for_IN objections_NNS ,_, if_IN any_DT ._.
Đầu ra: Câu chưa được POS Tagging
Upon such reading of any such certificate or paper , the President of the Senate shall call for objections [...]
Filed under: Lập trình Ruby, Thư viện code | Leave a Comment »
(1) Sử dụng biến toàn cục với Ruby
Sử dụng ký hiệu $ trước tên biến. Chẳng hạn $foo. Nói chung sử dụng biến toàn cục là nguy hiểm và ít nên dùng
Filed under: Laboratory notes, Lập trình Ruby | Leave a Comment »
(1) Đọc từng dòng của một file văn bản vào một mảng các string, loại bỏ các dòng trắng, các dòng được loại bỏ ký tự trắng ở đầu và cuối xâu# Read all lines in file with name @name into an array
def read2array(name)
fin = open(name, “r”)
larray = Array.new(0)
while line = fin.gets do
next if /^[\s\t]*\n/ [...]
Filed under: Lập trình Ruby, Thư viện code | Leave a Comment »
Đang lập trình ruby. Mình thích trình editor Meadow (made in Japan).
Có điều khi lập trình không có hightlight code rất khó chịu. Vì thế mình đã search cách cài đặt ruby-mode cho emacs. Đây là link
http://sodonnell.wordpress.com/2007/06/21/emacs-ruby-foo/
Lưu tạm link vào đây cái đã. Khi nào có thời gian sẽ dịch sau
Sau khi làm theo hướng [...]
Filed under: Lập trình Ruby | Leave a Comment »
Hàm inject
Nguyên mẫu:
enum.inject(initial) { |memo, obj| block}
enum.inject { |memo, obj| block}
Combines the elements of enum by applying the block to an accumulator value (memo) and each element in turn. At each step, memo is set to the value returned by the block. The first form lets you supply an initial value [...]
Filed under: Lập trình Ruby | Leave a Comment »