All,
I was wondering if anyone has an intermit enough knowledge of rubys 'require' to tell me if the following is valid ruby or not;
class Something
def initialize(mode)
case mode
when :one then require 'some_gem'
when :two then require 'other_gem'
end
end
end
s = Something.new
If so, would the require plac...
Does anyone know of a way of providing pass-through methods to provide something like the following but with added DRY?
class Cover
@some_class = SomeClass.new
def some_method
@some_class.some_method
end
end
ideally I would like to dry it up to something like this:
class Cover
@some_class = SomeClass.new
passthrough...
I want to link to a documentation of a file in RDoc. but the only way I could do is with the following markup:
configuration.rb[link:files/configuration_rb.html]
I would like to do it in a better way, something like this:
<file>configuration.rb</file>
Is there any existing markup rule to do this?
EDIT: of course I've tried without...
Hi.
I wanna to create mouse click events by ruby.
left-click, right-click
is there some library to do this?
thanks for your concerns.
...
Does anyone have a good regex for stripping all symbols (';.,_\$@!% the carriage return etc) from a string, without damaging any foreign characters (é 多 فا etc)? Non-regex would be even better, I suppose, but I don't see any Ruby or Rails methods that do this.
...
An application I inherited has the following action for updating a user's profile:
class UsersController < ApplicationController
# ...
def update
@user = current_user
if @user.update_attributes(params[:user])
flash[:notice] = "Successfully updated profile."
redirect_to root_url
else
flash[:error] = "Hrm...
Being still somewhat new to Ruby, I'm not sure how to do this... Let's say I have a method that takes a variable number of arguments:
def mytest(*args)
puts args.to_json
end
Obviously I can call it with whatever I like, such as:
mytest('one', 'two', 'three')
No problem. But what I need to do is call it with a dynamically-created se...
Is there a quick way to clean up a url that is malformed with a 2nd question mark instead of ampersand? i.e.
http://google.com?x=1?y=2
thx
...
This code works as expected (does nothing, even doesn't produce warning/errors):
l = lambda {|i|}
l.call(1)
This code produces warning (warning: multiple values for a block parameter (0 for 1)):
l = lambda {|i|}
l.call
And this code fails with error (ArgumentError: wrong number of arguments (0 for 2)):
l = lambda {|i, y|}
l.call
...
Ruby 1.9.1, OSX 10.5.8
I'm trying to write a simple app that parses through of bunch of java based html template files to replace a period (.) with an underscore if it's contained within a specific tag. I use ruby all the time for these types of utility apps, and thought it would be no problem to whip up something using ruby's regex sup...
I'm building a widget to show medal counts for the Olympics. I have a collection of "country" objects, where each has a "name" attribute, and "gold", "silver", "bronze" for medal counts.
List should be sorted:
1. First by total medal count
2. If same medals, sub-sort by type (gold > silver > bronze, ie. two golds > 1 gold + 1 silver)
3....
Given a situation such as:
module Extension
def self.included(recipient)
recipient.extend(ModelClassMethods)
end
module ModelClassMethods
def self.msg
puts 'Hi from module'
end
end
end
class B
include Extension
end
Why is B.msg not available?
>> B.msg
NoMethodError: undefined method `msg' for B:Class
...
belongs_to :keeper, :class_name => "Staff"
belongs_to "staff", :foreign_key => "keeper_id"
In my basic tests, these seem to be doing the exact same thing.
Are they indeed the same?
Is one better than the other?
...
Im trying to use Liquid Template Language in my Rails Application, i've watched Ryan Bates' video over at rails cast, i pretty much follow the instructions but it just doesnt seem to work!
When I try something like
@template = Liquid::Template.parse("Hi {{name}}")
@template.render('name' => 'toby')
I get
hi toby
but when i try so...
I have two models of concern, "Order" and "Kit"; each order has_one :kit
Each "Kit" has a 'cost' value. Within a controller I want to be able to sum together the costs for each 'order'.
Logically I thought this would make sense (but it doesn't work):
@revenue = Order.Kit.sum(:cost)
Any help would be appreciated. Thanks.
Example:...
Hi.
I'm looking for extensible linux editor(GUI) that may be extended with plugins written in ruby. Editor shouldn't be written in java or ruby.
Any ideas?
...
I was looking through some Rails source code and came across
# File vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 129
129: def target!
130: @target * ''
131: end
What does the * '' do? Is that multiplication by an empty string...? And why would you do that.
...
Hello,
I'm using Starling and Workling to process background tasks in my application, a Swoopo-style auction site. In this case the background task is a notification system that monitors auctions and notifies the winner. The monitor is invoked upon creation of the auction object. My problem is that my monitoring code can't find the auct...
This is one of those things that seems like it should be laughably easy but I'm stuck...
I need to open a CSV file that is stored in SHIFT_JIS encoding and decode it to Unicode and also encode in UTF-8. It sounds like this is pretty straightforward in ruby 1.9 but I'm not feeling particularly adventurous on my production Rails app, so I...
Hi,
I'm trying to retrieve a document when I have an object id - however, the query does not work.
@collection = @db.collection('Mylist')
@result = @collection.find({"_id" => params[:id]})
I've tried variations of the query - it always yields empty - however when I try a query on the collection such as below, that would work.
@resul...