I often prefer to do this:
a, b = lambda do |data|
[f1(data), f2(data)]
end.call(some_function(some_data))
instead of this:
data = some_function(some_data))
a, b = f1(data), f2(data)
or this:
a, b = f1(some_function(some_data)), f2(some_function(some_data))
Is there any negative consequence from using lambdas for almost ever...
How to use rails to do this?
mysql> SET @t1=1, @t2=2, @t3:=4;
mysql> SELECT @t1, @t2, @t3, @t4 := @t1+@t2+@t3;
...
Ruby 1.8.7. I'm calling read on a socket which has been opened and connected with:
socket = Socket.new(AF_INET, SOCK_STREAM, 0)
sockaddr = Socket.sockaddr_in(mp.port, mp.ip_address.ip)
begin
socket.connect_nonblock(sockaddr)
[...]
The connection is confirmed by calling select() and then connecting a second time looking for Errno::E...
Hi!
I'm trying out Ruby koans and found some tests using this _n_ , never seen it before what is it and how do I use it?
Example:
def test_objects_have_methods
fido = Dog.new
assert fido.methods.size > _n_
end
// John
...
I want to build a select tag with only specific days for example Mon ... Fri, how can I generate that in rails 2 ?
...
I installed RMagick on my MacOSX system and when I try it with IRB everything works fine:
~ $ irb -rubygems -r RMagick
irb(main):001:0> p Magick::Long_version
"This is RMagick 2.13.1 ($Date: 2009/12/20 02:33:33 $) Copyright (C) ..."
=> nil
But when I try to put this in a simple Ruby script:
#!/opt/local/bin/ruby
require "rubygems"
re...
Hi, I have a sinatra web application and a C++ library that I can 'require' in sinatra (ruby) using bindings created by swig.
I also have a second -very similar- library, in which the function names are partially the same as in the first one. When I require them both, the one that is loaded first 'wins', i.e. calls to the ambiguous fun...
Hii all,
In my Ruby code am able to generate messagebox but i would like to know how to see it at client side ,am running rails application means server is running on my machine and tha messagebox is also generating on my machine but am nor able not abble to see it client side anyone has any idea how to do that in ruby??
...
Hi,
I would like set up a polymorphic relation with accepts_nested_attributes_for. Here is the code:
class Contact <ActiveRecord::Base
has_many :jobs, :as=>:client
end
class Job <ActiveRecord::Base
belongs_to :client, :polymorphic=>:true
accepts_nested_attributes_for :client
end
When I try to access Job.create(..., :client_at...
Hi
I would like to parse a html page and extract the meaningful text from it. Anyone knows some good algorithms to do this?
I develop my applications on Rails, but I think ruby is a bit slow in this, so I think if exists some good library in c for this it would be appropriate.
Thanks!!
PD: Please do not recommend anything with java
...
I was just over looking at this question. The first thought that popped to my head was that ruby must have some sort of "as" type keyword like Python's import to help avoid namespace pollution. I've googled a bit but it seems that it's recommended to wrap your code in modules to avoid namespace problems with ruby. This seems problemat...
I have a collection of Episodes which is connected to a Season and a Show.
I need to display them as such:
Show title
....Season number 1
........Episode name
........Episode name
....Season number 2
........Episode name
........Episode name
My controller:
def index
@show_ids = Following.find_all_by_user_id(curre...
I have this form and a yes or no radio choice. The get_request_ids(song) basically gives me the ids i need.
<% form_tag '/somewhere' do -%>
<% [ 'yes', 'no' ].each do |status| %>
<%= radio_button_tag "group[]#{get_request_ids(song)}", "#{status}[#{get_request_ids(song)}]" %>
<%= status.humanize %>
<% end %>
<tr><td><%= subm...
I am setting up a server and decided to install the latest Ruby from source. I downloaded ruby-1.9.2-p0.tar.gz and installed that with no problems.
Next up, was installing Rubygems. Using the 1.3.7 I downloaded from Rubyforge I ran setup.rb and got the error:
./setup.rb: 13: Syntax error: "(" unexpected (expecting "then")
This is all...
Hi,
I'm trying to write a simple backup script in Ruby that copies a folder to a specific directory with a timestamp in its name.
My code is (simplified):
require 'Fileutils.rb'
time = Time.now
FileUtils.cp_r "C:/somefolder", "D:/somefolder_backup_#{time}"
But I keep getting
`fu_mkdir': Unknown error - mkdir failed (SystemCallError...
Possible Duplicate:
Rails - Cannot dup NilClass when using Single Table Inheritance
Hi guys,
I'm using Rails 2.3.8 and Ruby 1.8.7 under Windows (yes I know I should be using linux... don't have time to do that now =P)
I'm trying to make a simple STI model.
Where I have a class User and 1 subclass (BusinessContact) inheritin...
I have a Rails 3 app that defines some classes like normal. I am trying to figure out how to reopen one of those classes within a plugin (generated by "rails generate plugin ..."), and have both of the files (the file in the app itself and the file in the plugin) automatically reload on every request in development mode.
A simple exampl...
class Foo
@@default = "default"
p instance_variables
p class_variables
class << self
p instance_variables
p class_variables
# How do I access the @@default variable here?
end
end
...
I'm learning basic game programming using Ruby and Gosu. I've installed Gosu from RubyGems, and it is currently sitting in /usr/local/lib/ruby/gems/1.9.1/gems/.
The full path is /usr/local/lib/ruby/gems/1.9.1/gems/gosu-0.7.24-universal-darwin/.
When I'm working on my game script, I can execute the file just fine using the terminal comm...
I want to create tree with ruby.
Any link or code ?
I have two tables.
table1 fields
id
name
desc
table2 fields
id
table1_id
table1_parent_id
I want to fetch all the descendents for the specific object.
I have 1 row of table1.
t = Table1.first
On the basis of object t I want to fetch all it's children and children of childre...