how can I eliminate duplicate elements from an array of ruby objects using an attribute of the object to match identical objects.
with an array of basic types I can use a set..
eg.
array_list = [1, 3, 4 5, 6, 6]
array_list.to_set
=> [1, 2, 3, 4, 5, 6]
can I adapt this technique to work with object attributes?
thanks
...
There are plenty of resources available to a Java developer for getting a jump-start into Ruby/Rails development. The reverse doesn't appear to be true.
What resources would you suggest for getting up-to-date on the current state of java technologies? How about learning how to approach DRY (don't repeat yourself) without the use of meta...
Given the following code which creates an and condition, how do I make it create an or condition instead?
Country.first(:conditions=>{:media_code=>country_code, :code=>country_code})
...
I would like to write a module that provides active record like functionality on an array instance variable.
Examples of its use would be
x = Container.new
x.include(ContainerModule)
x.elements << Element.new
x.elements.find id
module ContainerModule
def initialize(*args)
@elements = []
class << @elements
def <<(e...
Hi,
I'm new to the Ruby and Ruby on Rails world. I've read some guides, but i've some trouble with the following syntax.
I think that the usage of :condition syntax is used in Ruby to define a class attribute with some kind of accessor, like:
class Sample
attr_accessor :condition
end
that implicitly declares the getter and setter f...
I'm hoping to integrate Mercurial into my Rails site. I want to run basic commands like status, summary, log, and maybe even clone. I'd like to interface directly with the Mercurial libraries and avoid doing any command line parsing via regex.
Mercurial is written in Python; I am using Ruby. So, I need Mercurial Ruby bindings. It seems,...
I've been working on a piece of software where I need to generate a custom XML file to send back to a client application. The current solutions on Ruby/Rails world for generating XML files are slow, at best. Using builder or event Nokogiri, while have a nice syntax and are maintainable solutions, they consume too much time and processing...
Is there a method that can act like read_all, as in instead of using TCPSocket.read(no_of_bytes), one can simply TCPSocket.read_all. I am sending objects first by YAML::dump'ing them then sending them but I don't know a way to get their size in bytes. Thanks in advance, ell. Oh and I am very, very new to any form of network programming s...
I’m in the process of creating a large single-page web-app using ext-js for the UI components with Rails on the backend. I’ve come to good solutions for transferring data using Whorm gem and Rails support of RESTful Resources.
What I haven’t come to a conclusion on is how to structure the UI and business logic aspects of the applicatio...
I have a simple sinatra application that needs to generate a file (via an external process), send that file to the browser, and finally, delete the file from the filesystem. Something along these lines:
class MyApp < Sinatra::Base
get '/generate-file' do
# calls out to an external process,
# and returns the path to the gene...
I have a app that needs to connect over a socket to a remote computer that now has multiple IP addresses. Is there a way to turn the remote Hostname or IP a list of all the IPs that the system has?
Possibly (Hostname | Ip) => (RemoteMAC) => IPs?
These will be windows server 2003/2008 machines.
...
A Ruby dev I know asked this; my answer is below... Are there other, better reasons?
Why do so many Ruby programmers do
"#{string}"
rather than
string
since the second form is simpler and more efficient?
...
Just updated albacore to version 0.14 and ran into a major problem.
My current environment is:
Ruby 1.9.1
Rake 0.8.7
Albacore 0.1.4
The problem is that as of now all my rake build throw a funny little exception:
undefined method 'push' for #<Enumerator:0x???????>
So far I have traced the problem to albacore msbuild.rb line 38 and...
I'm getting this weird error on my windows 7 computer when I am using the html2haml command with Haml 3 and Rails on Ruby 1.9:
-- control frame ----------
c:0017 p:-9593720 s:0052 b:0052 l:000051 d:000051 TOP
c:0016 p:---- s:0050 b:0050 l:000049 d:000049 CFUNC :require
c:0015 p:0026 s:0046 b:0046 l:000045 d:000045 TOP C:/Ruby/lib/ru...
Rake (like make) is able to have many targets/tasks specified on invocation. Is it possible for a rake task to access the list of tasks the user invoked, in order to do its job?
Scenario:
Consider a Rake-based build tool. A help task would like to know what tasks were also specified in order to print their usage and halt the build proc...
In Ruby, it seems that a lot of coerce() help can be done by
def coerce(something)
[self, something]
end
that's is, when
3 + rational
is needed, Fixnum 3 doesn't know how to handle adding a Rational, so it asks Rational#coerce for help by calling rational.coerce(3), and this coerce instance method will tell the caller:
# I know ...
I am passing the reference of name to *mod_name*, I modify the referenced object from within the method but the change is not visible outside of the method, if I am referring to the same object from all locations how come the value is different depending on where I reference it?
name = "Jason"
puts name.object_id #19827274
def mo...
Just like the title says, wanted for testing purposes.
Thanks!
...
Chinese people do not like numbers with a digit 4 in it. I am going to implement a membership program with membership numbers not including the digit 4, say:
number = 3
number.next.has4?
=> true
how the has4? method can be done (efficiently)?
** EDIT
Thanks for the answers, I performed simple benchmarking as a reference:
class...
is the ruby mysqlplus adapter production ready?
have a choice between:
1. mysql library by tmtm (has a pure ruby and c version)
2. mysqlplus by http://github.com/oldmoe/mysqlplus/
3. dataobjects (used my datamapper ORM)
4. em-mysql
Currently using the C version of the mysql gem, that is the oldest and most popular option.
Evented...