This question is not about how to use Enumerators in Ruby 1.9.1 but rather im curious how they work. Here is some code:
class Bunk
def initialize
@h = [*1..100]
end
def each
if !block_given?
enum_for(:each)
else
0.upto(@h.length) { |i|
yield @h[i]
}...
Hi ,
I am doing a hobby project to scrape the content of an ASP.net website using Ruby or PHP or Java . For example if the website url " www.myaspnet.com/home.aspx" . i would like to extract the unicode text content from home.aspx and paste it to a notepad . Is there any libraries available in any of the above mentioned languages ...
New to rails...so bare with me.
I successfully installed and set it up searchlogic for basic (keyword) searching. I have the following problem:
@search = Proposal.search(params[:search])
@proposals = @search.all
The above code works properly if I type in a keyword such as "red". It will bring up everything with red keyword. Or if I t...
Situation:
In a typical cluster setup, I have a 5 instances of mongrel running behind Apache 2.
In one of my initializer files, I schedule a cron task using Rufus::Scheduler which basically sends out a couple of emails.
Problem:
The task runs 5 times, once for each mongrel instance and each recipient ends up getting 5 mails (...
I have an array of in Ruby. I want to:
Get a subset of the elements based on their position in the array - say every 5th element. I can do this with each_index, or extend and create a select_with_index method.
Perform some operation on the subset that depends on the entire subset - let's say subset.map{|element| subset.sum - element}
T...
Hi!
My model looks like this (example):
class Bank < ActiveRecord::Base
has_and_belongs_to_many :currencies
# other stuff
end
When I want to get some bank from database i do:
bank = Bank.first :joins => :some_table,
:conditions => {
#some conditions
}
Now, is there any way to explicitly retrieve cu...
"abc".respond_to?(:sub) returns true, but String.respond_to?(:sub) returns false.
The second returns false, because it asks whether objects of the class Class have a method sub, as String is an Object of Class. It is the same for methods()…
How do I do these things and especialy respond_to?() without creating an Object of that class.
...
Hi all,
The following statement...
content_tag(:li, concept.title)
...returns something like:
<li>"My big idea"</li>
The following method definition, when called, returns the same:
def list_of_concepts(part)
content_tag(:li, concept.title)
end
As does...
def list_of_concepts(part)
content_tag(:li, part.concepts.first.title)
...
Will Ruby ever see a performance boost as Javascript has seen recently? Can a new VM make it really, really, fast? Or do we have to assume all the benefits of Ruby have an inescapable performance penalty?
What methods could be taken to improve its performance compared to other faster languages?
...
I think I'm going mad. Can anyone help?
I have the folder c:\project\bin
I run the following to execute my rake script
cd C:\project
rake
In my rake script I have:
require 'rake/clean'
CLOBBER.include('bin')
task :default => ["compile"]
task :compile do
# do nothing
end
It doesn't delete the "bin" folder nor the contents of ...
i'm interested with kestrel http://github.com/robey/kestrel/tree/master, is there any rubygems or library for connecting kestrel with ruby/rails?
thanks
...
I have a model called Book, which has_many :photos (file attachments handled by paperclip).
I'm currently building a client which will communicate with my Rails app through JSON, using Paul Dix's Typhoeus gem, which uses libcurl.
POSTing a new Book object was easy enough. To create a new book record with the title "Hello There" I could...
some thing like this:
John send a message to user1, user2, user3 and user4
this does not work
@users.collect{ |u| link_to(u.name, user_path(u)) }.to_sentence
...
I'd like to use a RubyGem in my C# application.
I've downloaded IronRuby, but I'm not sure how to get up and running. Their download includes ir.exe, and it includes some DLLs such as IronRuby.dll.
Once IronRuby.dll is referenced in my .NET project, how do I expose the objects and methods of an *.rb file to my C# code?
Thanks very muc...
I've developed a Ruby application (a small game), and I would like to 'distribute' it to other people.
However, I am not sure what to do about the required gems. If I just send my application to someone who have ruby installed, but not the required gems, I assume it will blow up. Can I package the gems locally? If so, would it conflict...
I'm writing a simple Rails model called Person that has_many :phone_numbers and I'm trying to save the phone numbers in a complex form without manually writing setter methods. accepts_nested_attributes_for should do what I want but I'm having trouble getting it to work. Here's the code I have so far:
Migration
class CreatePeople < Acti...
I am running a command using sh and need to read the output of that command. e.g.
sh "whoami"
But sh only seems to return true rather than a string containing the output of the whoami command. Does anyone know of a solution?
...
There have been a few posts about linkifying text using a regex. The most popular is this post.
However my spec is a little more tricky:
describe TextFormatter do
def l(input)
TextFormatter.gsub_links!(input){|link| "!!#{link}!!"}
end
it "should detect simple links" do
l("http://www.cnn.com").should == "!!http://www....
Greetings everyone:
I would love to get some infomation from a huge collection of Google Search Result pages.
The only thing I need is the urls inside a bunch of html tags.
I cannot get a solution in any other proper way to handle this problem so now I am moving to ruby.
This is so far what I have written:
require 'net/http'
require...
Since I've upgraded to snow leopard I've been having tons of problems using cucumber to run my features.
Currently, every time I run cucumber I get the following error.
Missing these required gems: webrat
cucumber >= 0.3.100 webrat >=
0.5.0 rspec >= 1.2.6 rspec-rails >= 1.2.6
You're running: ruby 1.9.1.243 at
/...