
Ruby
iteye_6281
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
ruby学习笔记
定义数组并使用block迭代:animals = %w(ant bee cat dog elk)animals.each{|animal|puts animal} ant bee cat dog elk 使用lambdm定义block为proc对象并使用call调用执行:def n_times(thing) return lambda{|n| ...原创 2013-01-24 00:29:37 · 113 阅读 · 0 评论 -
写文件并加载
这个例子写文件,然后用“load”加载并运行 5.times do |i| File.open("temp.rb","w") do |f| f.puts "module Temp" f.puts " def Temp.var" f.puts " #{i}" f.puts " end" f.puts "end" end原创 2013-01-29 12:11:25 · 101 阅读 · 0 评论 -
ruby线程
使用ruby线程require 'net/http'pages = %w{http://www.rubycentral.com http://slashdot.org http://www.google.com}threads = []for page_to_fetch in pages threads << Thread.new(page_to_fet...原创 2013-01-29 14:33:50 · 106 阅读 · 0 评论 -
Ruby 线程安全类 Monitor
使用Monitor进行线程的同步比较安全require 'monitor'class Counter attr_reader :count def initialize @count = 0 end def tick lock = Monitor.new lock.synchronize do @count += 1 end...原创 2013-01-29 16:05:03 · 251 阅读 · 0 评论 -
Ruby Thread Condition Variables
线程同步使用条件变量(Condition Variables)require 'monitor'SONGS = [ 'Blue Suede Shoes', 'Take Five', 'Bye Bye Love', 'Rock Around The Clock', 'Ruby Tuesday']START_TIME = Time.newdef...原创 2013-01-29 18:21:31 · 229 阅读 · 0 评论