Ruby声音
转 Adding Sound to Your Ruby Apps
Have you ever thought about including sounds in your Ruby application? Used sparingly, sound may enhance your applications by adding audio cues or a custom touch. You could, for example, play a beep or chime that announces the completion of a lengthy process. Perhaps a humorous sound to accompany an error message .
The win32-sound library makes using sounds really simple.
If you installed Ruby with the One-Click Ruby Installer, then you probably already have the win32-sound library installed, along with other win32 utilities. Otherwise, you can install it in seconds via gem. Open up a console window and enter..
gem install win32-sound
To use the win32-sound library, add these require and include statements to the top of your script...
require 'win32/sound'
include Win32
Then, to play a sound file on the PC, call the Sound.play method, passing it the name of the file...
Sound.play('chimes.wav')
Sound.play('c:\sounds\hal9000.wav')
In the example above, you don't have to include the path to the file 'chimes.wav', because 'chimes.wav' is usually installed in the Windows folder. But in most cases, you'll want to include the full path to the sound file.
To generate a simple beep, call the Sound.beep method, passing it the tone frequency (in Hertz, between 37 and 32767) and the duration in milliseconds. For example, to play a low tone for half a second...
Sound.beep(100, 500)
...or to play an annoyingly high-pitched tone for 3 full seconds...
Sound.beep(5000, 3000)
The complete docs for this library can be found here.
Distributing your sound files with your application is also simple. You can embed your sound files in an executable created with RubyScript2Exe, or include them in an install package produced with Inno Setup.
Be careful not to overdo it, though, if your program is to be used by others besides yourself. It's a fine line between clever and annoying.
注:
win-32声音库文件夹位置为
C:\WINDOWS\Media
Sound.pl
相关文档:
env setup
linux(ubuntu)下ruby开发环境搭建,包括一些常见问题解决
注意,本文只是我在搭建ruby学习环境时的一些笔记,因为是用gedit编辑的,所以格式化不是很好,另外,只是备忘而已。
2010.1.19
1. install ruby
$ tar xzf ruby-1.8.7-p248.tar.gz
$ mv ruby-1.8.7-p248 ruby187
$ cd ruby187/
$ ./configure
......
转自:http://developer.51cto.com/art/200912/170762.htm
Ruby字符串处理函数总结列表分享
Ruby字符串处理函数包括返回字符串长度函数;判断字符串中是否包含另一个串函数;字符串插入;字符串分隔,默认分隔符为空格等等。
str.length => integer
str.include? other_str
&nbs ......
The following is improved version of the code created by David Mullet, from
http://rubyonwindows.blogspot.com/2007/03/ruby-ado-and-sqlserver.html
require 'win32ole'
class SqlServer
# This class manages database connection and queries
attr_accessor :connection, :data, :fields
attr_wr ......
1,安装ruby
下载地址: http://rubyinstaller.org/download.html
2,安装rails
使用命令下载:在命令行运行gem install rails --remote
2,初步了解ruby的文章
http://www.bcbbs.net/html/29671.html
http://www.bcbbs.net/dev/List64.aspx ......