Tagged Questions
1
vote
1answer
48 views
Why don't the following Ruby methods work? I've written a couple of methods that are supposed to give the sum of an entered array
This is what's up:
It seem I've got a syntax problem. Both of the following methods, which are similar to one another, load to irb fine. When I go to use them, though, they produce errors. Since I'm ...
0
votes
1answer
32 views
DataMapper fetching last record using .last throws no method error if using .any? in view
Apologies for the long wined title, in my app I am trying to retrive e the last record from the database that matches the params I have passed to it.
@goals = ...
0
votes
1answer
32 views
Ruby: Applying filters to text files (conditional printing)
I have a CSV that has three types of info:
userID,wordID,ct
(Basically, 14k different tweeps, a different line for each word they use, including a count for that word)
I would like to be able to ...
3
votes
3answers
52 views
Converting a sequence of numbers to conditionals/ranges
I have an array that consists of pairs of a numeral and some value:
a = [[2, :foo], [5, :bar], ..., [17, :baz]]
where it can be assumed that no two pairs have the same numeral, and the pairs are ...
0
votes
1answer
166 views
ruby on rails if statement always returns true
controller code:
def create
if current_user.id != params[:friend_id]
@return = { :curr_user_id => current_user.id, :params_id => params[:friend_id], :debug => 1 }
else
...
0
votes
1answer
80 views
Is it possible to “dynamically” join a table only if that table is not joined yet?
I am using Ruby on Rails 3.2.2 and I would like to know if in scope methods it is possible to "dynamically" join a table only if that table is not joined yet. That it, I have:
def ...
0
votes
3answers
76 views
Only calling a method if a hash is populated
I have an instance variable called
@filtered_ratings = params[:ratings].keys
However, if params[:ratings] is nil and #keys is called on it there is an error that is raised. If @filtered_ratings ...
6
votes
4answers
717 views
Ruby - Access multidimensional hash and avoid access nil object [duplicate]
Possible Duplicate:
Ruby: Nils in an IF statement
Is there a clean way to avoid calling a method on nil in a nested params hash?
Let's say I try to access a hash like this:
...
2
votes
2answers
222 views
How to make conditional styles in Paperclip?
I'm trying to make Paperclip convert every image to JPG unless it is an animated gif. Is there any way to specify a conditional style or I have to make a processor?
10
votes
4answers
904 views
build a ruby gem and conditionally specify dependencies
I am working on a gem that has needs to set dependencies conditionally when the gem is installed. I've done some digging around
and it looks like i'm not alone in this need.
Rubygems: How do I add ...
0
votes
2answers
1k views
Conditional Callback in Rails' model?
Just wondering if there is a way to do a conditional callback in Rails. I know you can do a conditional validation like so:
validates_uniqueness_of :email, :if => (1==1)
I often do things like ...
0
votes
3answers
50 views
Is there a concise way to return the numerical iterator in a loop in Ruby?
It seems like there should be a one-liner way to iterate over season and return the last season when show.has_season? evaluates to false.
def last_season(show)
season = 1
season += 1 while ...
9
votes
7answers
1k views
Building a hash in a conditional way
I am using Ruby on Rails 3.0.10 and I would like to build an hash key\value pairs in a conditional way. That is, I would like to add a key and its related value if a condition is matched:
hash = {
...
0
votes
3answers
140 views
Python If Condition with two conditions dependent on a tuple
I have only recently begun programming in Python (with previous Ruby experience). I am trying to set up an if condition with two conditions:
if not previous[1] and previous[0][0] == 5:
...
0
votes
2answers
459 views
Using a Regular Expressions as a conditional loop (until)
I'm trying to use a regular expression as a condition inside (until) loop.
basically, It's for entering numeric password..
I tried this code
print "Password: "
x = gets.chomp.to_i
until ...