I have a simple array:
arr = ["apples", "bananas", "coconuts", "watermelons"]
I also have a function f that will perform an operation on a single string input and return a value. This operation is very expensive, so I would like to memoize the results in the hash.
I know I can make the desired hash with something like this:
h = {}
a...
Hi,
Here is my simple text search code:
def search
@cart = find_cart
@products =Product.find(:all,
:conditions => ["title LIKE ? || body LIKE ? || maker LIKE ?", "%#{params [:search]}%", "%#{params[:search]}%", "%#{params[:search]}%"])
if @products.size ==0
flash[:notice] = "Please check the spelling "
end
I would like to a...
Hi there.
It's rather hard to find any documentation on Mocha, so I'm afraid I'm totally at sea here. I have found a problem with stubbing methods that pass arguments. So for instance if I set up a class like this:
class Red
def gets(*args)
@input.gets(*args)
end
def puts(*args)
@output.puts(*args)
end
def initial...
I have Ruby 1.9.1 installed and by default RubyGems is required. As such, my load path has all my gems included. Is there a way to run Ruby 1.9 without having RubyGems required?
...
Hi,
I have started learning Ruby for the past 2,3 weeks and I have come up with some findings on the language. Can someone please validate these points.
Implemented in many other high level languages such as C, Java, .Net etc.,
Is slow for the obvious reason that it cannot beat any of the already known high level languages.
Should nev...
I want to write a "client" for megaupload.com in Ruby and I wanted to know if there was a captcha solver / decoder / autofiller for Ruby.
Thanks
...
I have a bunch of rake building tasks.
They each have unique input / output properties, but the majority of the properties I set on the tasks are the same each time. Currently I'm doing that via simple repetition like this:
task :buildThisModule => "bin/modules/thisModule.swf"
mxmlc "bin/modules/thisModule.swf" do |t|
t.input = "s...
I am on Ubuntu10
sudo apt-get install ruby1.9.1-full
then download sources of rubygem 1.3.7 and install it
sudo ruby setup.rb
then, for example, install sinatra
sudo gem install sinatra
Finally open irb and type
require "rubygems"
require "sinatra"
and get error
LoadError: no such file to load -- sinatra
from (irb):2:in ...
Hi, I have just started learning ruby on rails. I have a doubt wrt routing.
Default Routing in Rails is :controller/:action/:id
It works really fine for the example lets say example.com/publisher/author/book_name
Could you tell me how do you work with something very big like this site
http://www.telegraph.co.uk/sport/football/leagues...
What are rails smart collections?
If I am trying to build a view that presents most popular articles, top 10 products, recent comments (i.e a snapshot of recent updates to a variety of models in one view), would I be using a smart collection?
Would I be updating it via something like delayed job? Use some sort of fragment caching?
Wha...
I am trying to get my TagsController#index action to display only the Questions that contain certain tags when passing the search parameter tag_name. I am not getting an error just can't get the filter to work correctly such that upon receiving the /tags?tag_name=something url, only those questions are displayed . Here is the setup:
cla...
How many user agents are there in Mechanize? Is there a handy list of all the user agent options anywhere?
...
Hi everyone.
For as long as I can remember, I've always had a "favorite" language, which I use for most projects, until, for some particular reason, there is no way/point on using it for project XYZ. At that point, I find myself rusty (and sometimes outdated) on other languages+libraries+toolchains. So I decided, I would just use some l...
I have a requirement to handle custom date formats in an existing app. The idea is that the users have to do with multiple formats from outside sources they have very little control over. We will need to be able to take the format and both validate Dates against it, as well as parse strings specifically in that format. The other thing is...
Normally, I might get the metaclass for a particular instance of a Ruby object with something like this:
class C
def metaclass
class << self; self; end
end
end
# This is this instance's metaclass.
C.new.metaclass => #<Class:#<C:0x01234567>>
# Successive invocations will have different metaclasses,
# since they're different ins...
I have successfully set up this plugin before so I am curious as to what I am doing wrong here. I have built the ability for users to add tags to questions. I am not using tagging plugin here but that shouldn't matter for this.
With respect to the auto complete, I am trying to have the form located in the /views/questions/show.html.erb...
Want to use RMagick to create a PNG image of a gradient that goes from rgba(0,0,0,0.3) to rgba(0,0,0,0.7). Is this possible?
...
I'm stumped on what's causing this. I get this error and stack trace in all my functional tests where I call 'post'. Here is the full stack trace:
7) Error:
test_should_validate(UsersControllerTest):
ArgumentError: wrong number of arguments (1 for 0)
/Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/...
Can Mechanize make Javascript calls?
This would be handy to negotiate AJAX when screen-scraping...
...
Hi,
I was trying to use active record store but I kept getting an invalid authenticity token. Someone told me to remove my protect_from_forgery from application controller. I know that this would remove all auth tokens but I'm not sure if this is a good idea. Does active record store not need auth tokens?
By the way, all I need is a wa...