November 29, 2007 at 6:16 pm
· Filed under 1.9, Ruby, irb
Wirble, which is awesome, uses syntax in its case blocks that break Ruby 1.9.0. It’s too bad. Wirble makes irb so much nicer to look at and use (although, I do have to say that I don’t use its prompt or history features, but maybe only through old stubbornness).
Anyway, if you’re using 1.9 alongside 1.8, it’s nice when everything works the same. And so, here’s a simple patch for wirble.rb (the only file when you install the gem). Apply it to your gems/1.9/gems/wirble-0.1.2/wirble.rb (usually in /usr/local/lib/ruby/) and there you go.
Permalink
November 21, 2007 at 2:33 pm
· Filed under Rawdio, Ruby
I’ve wrapped up my WAV file wrapper and stuffed it into a gem. As it stands it can only take audio data as a byte string and write a WAV file for it, but sine/square/triangle wave helpers (and more!) are on their way. I’m also hoping to add support for other “raw” audio formats soon.
require 'rubygems'
require 'rawdio'
white_noise = Rawdio::WAV.new
8000.times { white_noise << rand(255).chr }
white_noise.write('sweet_sound.wav')
Have at it (if you have the need):
sudo gem install rawdio
Permalink
November 16, 2007 at 11:48 am
· Filed under Ruby
Well, my current development job is coming to an end and I’m back looking for a job again. It was great having a Ruby (not Rails) job, and I’d love to find one again. (Although, I should say that I have nothing against Rails.)
When I started at the company, our first milestone loomed large and imposing, but at the end we were surpassing milestones well in advance and on target to stroll through our New Year’s goal by December first. It’s unfortunate that most of that work will never see the light of day, but such is life in a start-up, I suppose.
I’m around, looking for work, if anyone needs me.
Permalink
November 13, 2007 at 12:27 am
· Filed under Guess Method, Ruby, irb
I’m starting to see a pattern. I make one change to GuessMethod, release it, then think of something else almost immediately and release again. And such brings us to 0.1.2.
I almost called this one 0.2 because I think I finally figured out how GuessMethod should really work, which is this way:
- Call the original method_missing or const_missing and let it go through unless…
- it raises a NameError or NoMethodError, in which case…
- capture the error and…
- try to guess.
If the guess is successful, apply the guess. If not, raise the original error.
Now this all seems so obvious. But so much is in hindsight.
Anyway, don’t let anyone try to trick you into thinking this is somehow something to be used in production, or even outside of irb. This doesn’t belong anywhere except in irb.
I’ve been trying to think of how to put this in your .irbrc so that things go the best way possible. I think this is it:
require 'guessmethod' if defined?(IRB) and not ENV.has_key?('RAILS_ENV')
Go get it. I swear I wouldn’t work on this unless it made irb more fun, which it totally does.
Permalink
November 8, 2007 at 7:16 pm
· Filed under Guess Method, Rails, Ruby
It finally happened. I figured out how to get GuessMethod (particularly the GuessConstant half of things) and Rails to behave. There’s still a little kludginess to it, but they can work magic together:
mvb:~/rails/depot cms$ script/console
Loading development environment.
>> require 'guessmethod'
=> ["GuessMethod", "GuessConstant", "GuessMethodOptions", "GuessMethodGuesser", "GuessMethodOutputter"]
>> LineItm.find(:first)
no constant in threshold: for LineItm, sending to Object's const_missing
NameError: uninitialized constant LineItm
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:266:in `load_missing_constant'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:452:in `const_missing'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:464:in `unguessed_const_missing'
from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.1.0/lib/guessmethod.rb:87:in `const_missing'
from (irb):2
>> LineItem
=> LineItem
>> LineItm.find(:first)
attention: replacing non-existant constant LineItm with LineItem for Object
=> #<LineItem:0x30c1338 @attributes={"order_id"=>"1", "total_price"=>"3", "quantity"=>"1", "product_id"=>"8", "id"=>"1"}>
Once Rails loads a constant GuessConstant can find it, and your poor typing stops holding you back.
There’s just one thing (there’s always just one thing). Things don’t go very well if you require GuessMethod in your irbrc. You have to require it manually in the console. It works fine when script/server gets a hold of it, but not for script/console. I suppose they load everything in a different order (but this isn’t something I’ve looked into yet). Rails has to show up to the dance first.
It was this old Dr. Nic post that got me over the hurdle solving this one. Thanks Dr. Nic.
sudo gem install guessmethod
Enjoy!
Permalink
November 4, 2007 at 1:58 pm
· Filed under Ruby
It looks like M. Edward (Ed) Borasky is about to start a ruby blog. He’s on (in a matter of speaking) the comp.lang.ruby high score list.
Permalink