ruby

explain the code - custom class definition & use (ruby)

could somebody explain the code below for me? Only the lines where is #??? I asked and got an answer It does 100% what I asked for. Now I need to add some code and I do not know where. I tried and it did not work. I used custom class in ruby twice so far otherwise I used to use arrays. Is it actually custom class used below? :-) I nee...

Get mimetype from filename

MIME::Types.type_for(filename) What gem do I need to install, and what file do I need to require to use that? ...

library/module or my code? what is better? (ruby)

I asked my question and got two answers one is piece of code and the other one is to use a library/module. I am wondering what is better to use. Does it actually matter? Is there any difference in speed, code update or in any other way? in my case the code is only a loop with 2 lines... My questions is more in general from somebody who...

Yaml'ifying an XML file?

I want to take an XML file (example is http://xboxapi.duncanmackenzie.net/gamertag.ashx?Gamertag=xpaulbettsx) and just turn it into a Ruby dictionary / ExpandoObject type thing, so I can do something like gamertag_info = HowDoIDoThisPart.load("Example.xml") puts gamertag_info.zone >>> "Underground" puts gamertag_info.recentgames >>> <Ar...

Ruby gsub problem when using backreference and hashes.

The following code defines a hash with regular expressions (keys) and replacements (values). Then it iterates over the hash and replaces the string accordingly. Simple string substitution works well, but when I need to compute the resut before substituting it (the case of years to days change), it does not. And it is key that the hash ...

Ruby Gems on Windows

I have removed and reinstalled ruby on my machine (windows 7, ruby 1.9.1). When I go to get rails again I get: While executing gem... File Exists C: Yet when I list my gems is says none are installed. What gives? ...

Ruby gem already activated

How can I de-activate the newer version of cucumber, or get this to work with the earlier version? user$ rake features (in /Users/user/Project) /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I "/Library/Ruby/Gems/1.8/gems/cucumber-0.6.1/lib:lib" "/Library/Ruby/Gems/1.8/gems/cucumber- 0.6.1/bin/cucumber" --form...

Ruby block to string instead of executing

Hello, Take this example: write_as_string { puts 'x' } I then want to be able to do def write_as_string(&block) puts block.to_s end When I execute this, I want the output to be: "puts 'x'" I want to be able to receive the block and get the actual code for the block instead of executing it. Motivation: Creating a DSL, I want...

Rake Task Ordering

Suppose I have two top-level tasks: task :publicBuild => [:zipSourceCode, :copyPrivateKey] task :internalBuild => [:copyPrivateKey] For the internalBuild task, I don't want to zip source code - I just want the private key. But for a publicBuild, I want to do both. But I need to guarantee that for the publicBuild, the zipSourceCode tas...

Simple quantity function problems, shopping cart

I just picked up Agile Web Development with Rails 3rd Ed., and I'm going thru the Depot Application chapters, I'm attempting to create a simple Edit quantity function, and delete function. I've had luck with the delete function but no luck with the edit quantity function. I'm going to provide a lot of information, so please don't feel ...

What's the best way to test this?

I'm going through the EdgeCase Ruby Koans. In about_dice_project.rb, there's a test called "test_dice_values_should_change_between_rolls", which is straightforward: def test_dice_values_should_change_between_rolls dice = DiceSet.new dice.roll(5) first_time = dice.values dice.roll(5) second_time = dice.values ...

SMTP errors at sendig emails with ruby on rails

I've been trying to send some test newsletter using my gmail account as smtp, but when i tried to send to multiple recipients - ['emai@[email protected], [email protected]'] - in this case the first email address is incorrect - it gives me an error 555 - 5.5.2 Syntax error and the process stops without passing through the next email add...

Thinking Sphinx - Search filter not working

Hi, I installed Sphinx and Thinking Sphinx on ruby-on-rails 2.3.2 and on Windows 7 pc. First of all, if I run rake ts:start, it won't start at all. It keep saying "Starting..." and it never starts. Even though, the simple search(with no filtering nor conditions) works fine. When I try to add a filter, it won't return any record. My mo...

Ruby: difference between || and 'or'

It is really hard to google this, because neither || nor 'or' are good words to search for :) I am wondering if there is a difference between the two, or if it is just a matter of preference? ...

Possible to access the index in a Hash each loop?

I'm probably missing something obvious, but is there a way to access the index/count of the iteration inside a hash each loop? hash = {'three' => 'one', 'four' => 'two', 'one' => 'three'} hash.each { |key, value| # any way to know which iteration this is # (without having to create a count variable)? } ...

Calling a Method from Within a Ruby Class? (or is this rails magic)

I'm new to Ruby and working through some tutorials/screencasts. I've reached the section where they're discusisng the before_filter callback, and it's using some syntax that's a little weird for me. I don't know if it's a feature of ruby, of if it's some rails magic, and was hoping someone here could set me straight or point me in the ...

Ruby class variables

The ruby class-instance stuff is giving me a headache. I understand given this... class Foo @var = 'bar' end ...that @var is a variable on the created class's instance. But how do I create a sub-class overridable class variable? Here is an example of what I would do in Python: class Fish: var = 'fish' def v(self): return sel...

Database query within actionmailer

I have a problem, I'll simplify it down to the blog example. 1) Each 'post' is created by a different user stored in a 'User' database. 2) Several 'comments' belong to the one 'post'. 3) When a new 'comment' is made, the user who created the initial 'post' needs to be emailed. I have setup the mailer and observer. I am just not sure how...

How to search for useful ruby gems

What are good sites to look for useful ruby gems? ...

ruby prawn how to wrap text around an aligned right image ?

Hi all s it posible to align an image to the right and wrap text around the image like it is in html and css using the float:right property ? If so how do you do this ? I can align an image but dont't know how to wrap the text around it. The text is dynamic text therefore varies alot in length. Thanks alot Rick ...