Hi all, I really sorry 'cause I never write at this blog for very long time :D. I want to try to start it again with a small share information. This article is very interested me to figure out about how to programming it with Ruby. Sorry if this blog just like a bookmark.
May be we can try to make ruby as our base language programming.
Normally,when ruby is not able to find the method,it usually raises
"NoMethodError: undefined method "methodname"".That's what we always stuck,nothing special.
Above all,because of Ruby is a kind of dynamic language,what it does exactly if it can't find the method is calling "method_missing" method and method_missing raises a NameError exception,what is the point? you're able to apply the method_missing method in your application and do something cool.When we use hash,we normally call hash["key"] or hash[:key].What if we would like to call it something like hash.key.And here is a bit tricky used of it.
def method_missing( id, *args ) if self[id].nil? m = id.to_s if /=$/ =~ m self[m.chomp!] = (args.length < 2 ? args[0] : args) else self[m] end else self[id] end end h = { "foo" => "bar",:blah => "thinkruby"} h.blah # => thinkruby h.foo # => bar
It's not bad,right?
Mostly,we listen audio files in mp3 ,but sometime we have the audio in other formats.Then how to trancoding it to mp3?
And again using powerful ruby library always help us.Like today I'd like to show you guys with
R2mp3 library which intends to convert all audio files on the planet to mp3 with super simple Ruby code and currently support wma,m4a(aac),ra(rm).
Requirement software
(on Ubuntu)
$sudo apt-get install mplayer lame
(on OS X)
$sudo port install mplayer lame
Install the library
$sudo gem install r2mp3
or
$svn checkout http://r2mp3.rubyforge.org/svn/trunk/ r2mp3
Start Coding
require 'rubygems' # if install using gem require 'r2mp3' Converter.new(:convert=>:wma,:file=>"test.wma"){|f| f.to_mp3 }
test.mp3 is already there.Thanks R2mp3.
We don't need to download any fancy gui programs,do we? :)
Here are Ten libraries you must have in the box.
1. Zlib
2. Digest::MD5
3. StringIO
4. Tempfile
5. Readline
6. Find
7. YAML
8. dbm
9. Pathname
10. OptionParser
Fully pointed out by [Doug Beaver]
(It's a bit old article,but it's all great libs)
This is just another "Hello World" blog (not in-depth one) about well-known GUI library,so called "Qt".You probably take a look at Trolltech's [How to Learn Qt] tutorial.
[Keep in mind that like most documents about Qt, it is very C++ oriented.]
And I use Qt4 for this example.
This example shows how to create Ruby program with Ruby bindings for Qt4
The underlying code is where you are able to start
require 'Qt' app = Qt::Application.new(ARGV) window = Qt::Widget.new() hello = Qt::PushButton.new('Hello!,Qt'+Qt::qVersion,window) quit = Qt::PushButton.new('Quit', window) quit.setGeometry(10, 40, 80, 40) Qt::Object.connect(quit, SIGNAL('clicked()'), app, SLOT('quit()')) window.show() app.exec()
you will see something like this:


