首页 软件开发 代码片段 ruby ( Page 31 )

ruby 388

#Ruby
ruby四种魔法写法

def i(a='') print a end def love(a='') "Hello " + a end def you "world! \n" end i love you…

2014-11-20 946

#Ruby
Ruby菜鸟解决"易语言难题”

require 'set' p (123..329).map { |i| [i, i<<1, i*3] if Set.new("#{i}#{i<<1}#{i…

2014-11-20 181

#Ruby
约数求和

def divisors(n) sumOfDivisors=0 i=1 while i<n if n%i==0 divisor=i sumOfDivisors=sumOfDi…

2014-11-18 833

#Ruby
Ruby 之 Tk 创建新窗口

#!/usr/bin/env ruby require 'tk' hello = TkRoot.new TkLabel.new( hello ) do text "\n Hello…

2014-11-15 223

#Ruby
网页图片抓取

module CommonHelper require 'nokogiri' require 'open-uri' def down_load_xmz site_url = "ht…

2014-11-12 227

#Ruby
Ruby简单的串口通信

def serialport_command(command) result = "" File.open("COM3","w+") do |sp| sp.write(comman…

2014-11-12 114

#Ruby
Ruby 从 Berkeley DB 数据库保存和获取数据

require 'bdb' db = BDB::Hash.create('r2.db', nil, BDB::CREATE) db['W'] = 'i' db.close db =…

2014-11-12 409

#Ruby
Ruby 连接到 TCP 服务器并读取回应

require 'net/telnet' server = Net::Telnet::new('Host' => 'http://www.rubyinside.com/', …

2014-11-12 281

#Ruby
裴波那契数列ruby实现

def fib n i = 2 a ,b = 1, 1 while i < n a,b = b, a+b i += 1 end b end p fib 16 #打印987

2014-11-08 1,003

#Ruby
Ruby 一个简单的 SSH 客户端

require 'rubygems' require 'net/ssh' Net::SSH.start('example.com', :username=>'userName…

2014-11-07 690

#Ruby
ruby decryption

#author linxu #decrypt the message of cipher.txt module RubyTrain SPLIT_KEY = ":" class De…

2014-11-07 743

#Ruby
Ruby 使用 OpenGL 的例子

require "opengl" require "glut" $light_diffuse = [1.0, 0.7, 0.7, 1.0] $light_position = [1…

2014-11-06 509