![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
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 · 70 阅读 · 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 · 66 阅读 · 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 · 70 阅读 · 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 · 202 阅读 · 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.new def...原创 2013-01-29 18:21:31 · 154 阅读 · 0 评论