Testing and assigning with regexp's

I'm new to Ruby, and in a little program I'm writing, I have code like this:

str = ''
if /something/.match(str)
    str = /something/.match(str)[1]
end

Is there a more elegant way to do this?

Mike Steiner

str = $& if str =~ /something/

Although, running this when str == '' is pretty useless.

···

On May 2, 10:20 am, "Mike Steiner" <mikejaystei...@gmail.com> wrote:

I'm new to Ruby, and in a little program I'm writing, I have code like this:

str = ''
if /something/.match(str)
    str = /something/.match(str)[1]
end

Is there a more elegant way to do this?

Mike Steiner

Mike Steiner wrote:

I'm new to Ruby, and in a little program I'm writing, I have code like this:

str = ''
if /something/.match(str)
   str = /something/.match(str)[1]
end

Is there a more elegant way to do this?

Mike Steiner

str = ''
m = /something/.match(str)
str = m[1] if m

···

--
RMagick [http://rmagick.rubyforge.org]
RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html\]

A useful pattern is:
    str = $1 if /(something)/ =~ str

or without the capture:
    str = $& if /something/ =~ str

···

On Wed, May 02, 2007 at 08:23:13PM +0900, Tim Hunter wrote:

Mike Steiner wrote:
>I'm new to Ruby, and in a little program I'm writing, I have code like
>this:
>
>str = ''
>if /something/.match(str)
> str = /something/.match(str)[1]
>end
>
>Is there a more elegant way to do this?
>
>Mike Steiner
>
str = ''
m = /something/.match(str)
str = m[1] if m

Hi,
  I'm trying to pass an object from the View to the controller as a hidden field.

  Two quick questions:
  For a hidden field, how do I pass a complete object to the controller?
  For example, I have an object of type Issue, what should the second argument be in the
following:

   <%= hidden_field("issue", ?, "value" => @issue) %>

  Secondly, how would I access this object in the controller?
  
  Any help would be appreciated.

Thanks,
Anupam.

Tim Hunter <TimHunter@nc.rr.com> writes:

Mike Steiner wrote:

I'm new to Ruby, and in a little program I'm writing, I have code
like this:

str = ''
if /something/.match(str)
   str = /something/.match(str)[1]
end

Is there a more elegant way to do this?

Mike Steiner

str = ''
m = /something/.match(str)
str = m[1] if m

str = str[/something/, 1] || str

···

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

Agnisys wrote:

Hi,
  I'm trying to pass an object from the View to the controller as a hidden field.

  Two quick questions:
  For a hidden field, how do I pass a complete object to the controller?
  For example, I have an object of type Issue, what should the second argument be in the
following:

   <%= hidden_field("issue", ?, "value" => @issue) %>

  Secondly, how would I access this object in the controller?
    Any help would be appreciated.

Firstly:

Please don't start a new topic by hitting "Reply" in your mail application. This messes with the threaded view used by a significant number of users, and you might not get answers.

Secondly:
The Rails groups can help you more with this question, I guess:

···

--
Phillip "CynicalRyan" Gawlowski
http://cynicalryan.110mb.com/
http://clothred.rubyforge.org

Rule of Open-Source Programming #5:

A project is never finished.

I really do not understand, what you want to do. Which sense does it make,
to pass an entire object into a form and back to the controller,
when you do not want to manipulate it in the form? You could store it in
the session instead or fetch it from the database, when it lives there
after you got the form posted back.

From your posting one can assume, that you do not know nothing about rails
at all, then I would recommend to search http://www.rubyonrails.org/ for a
tutorial and http://api.rubyonrails.org/ for the APIs documentation or
read a book like "Agile Web Development with Rails" from Dave
Thomas and David Heinemeier Hansson.

If you want more help here, please describe your problem more detailed.

Regards
Thomas

···

On Wed, 02 May 2007 21:03:00 +0900, Agnisys wrote:

You will need to pass the id and then get the object from the db using the
id in the controller.

Secondly - ruby is the language in which rails is developed. This list is
for the language, which is used for more than just rails, so posting rails
questions to this list is annoying to people who have nothing to do with
rails.

For rails related questions join the rails mailing list:

Regards
Ivor

···

On 5/2/07, Agnisys <agnisys@yahoo.com> wrote:

Hi,
  I'm trying to pass an object from the View to the controller as a hidden
field.

  Two quick questions:
  For a hidden field, how do I pass a complete object to the controller?
  For example, I have an object of type Issue, what should the second
argument be in the
following:

   <%= hidden_field("issue", ?, "value" => @issue) %>

  Secondly, how would I access this object in the controller?

  Any help would be appreciated.

Thanks,
Anupam.

In that vein,
str.gsub!(/\A.*(something).*\z/, '\\1')

···

On 5/4/07, Christian Neukirchen <chneukirchen@gmail.com> wrote:

Tim Hunter <TimHunter@nc.rr.com> writes:

> Mike Steiner wrote:
>> I'm new to Ruby, and in a little program I'm writing, I have code
>> like this:
>>
>> str = ''
>> if /something/.match(str)
>> str = /something/.match(str)[1]
>> end
>>
>> Is there a more elegant way to do this?
>>
>> Mike Steiner
>>
> str = ''
> m = /something/.match(str)
> str = m[1] if m

str = str[/something/, 1] || str

--

Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

But what about people, who do not want to use ugly webforums or
even-more-ugly mailing lists which flood their mailboxes?

Do you know about a newsgroup where one can discuss rails topics?

Regards
Thomas

···

On Wed, 02 May 2007 23:42:09 +0900, Phillip Gawlowski wrote:

Secondly:
The Rails groups can help you more with this question, I guess:
Ruby on Rails — Community

Thanks Igor for you useful response. I would try the Rails community.
I didn't realize this is a Ruby ONLY list.

Anupam.

···

--- Ivor Paul <ivorpaul@gmail.com> wrote:

You will need to pass the id and then get the object from the db using the
id in the controller.

Secondly - ruby is the language in which rails is developed. This list is
for the language, which is used for more than just rails, so posting rails
questions to this list is annoying to people who have nothing to do with
rails.

For rails related questions join the rails mailing list:

Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

Regards
Ivor

On 5/2/07, Agnisys <agnisys@yahoo.com> wrote:
>
> Hi,
> I'm trying to pass an object from the View to the controller as a hidden
> field.
>
> Two quick questions:
> For a hidden field, how do I pass a complete object to the controller?
> For example, I have an object of type Issue, what should the second
> argument be in the
> following:
>
> <%= hidden_field("issue", ?, "value" => @issue) %>
>
> Secondly, how would I access this object in the controller?
>
> Any help would be appreciated.
>
> Thanks,
> Anupam.
>
>
>
>
>
>

zaphod wrote:

Secondly:
The Rails groups can help you more with this question, I guess:
Ruby on Rails — Community

But what about people, who do not want to use ugly webforums or
even-more-ugly mailing lists which flood their mailboxes?

What do you think is *this*? If you don't want to use the sources of information that are available to you, you are out of luck, harsh as it may sound.

Do you know about a newsgroup where one can discuss rails topics?

Very first entry on this website:

···

On Wed, 02 May 2007 23:42:09 +0900, Phillip Gawlowski wrote:

--
Phillip "CynicalRyan" Gawlowski
http://cynicalryan.110mb.com/
http://clothred.rubyforge.org

Rule of Open-Source Programming #15:

If you like it, let the author know. If you hate it, let the author
know why.

zaphod wrote:

Secondly:
The Rails groups can help you more with this question, I guess:
Ruby on Rails — Community

But what about people, who do not want to use ugly webforums or
even-more-ugly mailing lists which flood their mailboxes?

What do you think is *this*?

A news group about "ruby"? As far as I understood your last posting,
comp.lang.ruby is not for discussing rails topics.

Do you know about a newsgroup where one can discuss rails topics?

Very first entry on this website:
Ruby on Rails — Community

The very first entry "general list" is not a news group but a google
group, for which I need a google account - or am I wrong and there is a
way to use them in my newsreader via nntp?

Ragards
Thomas

···

On Thu, 03 May 2007 00:09:46 +0900, Phillip Gawlowski wrote:

On Wed, 02 May 2007 23:42:09 +0900, Phillip Gawlowski wrote:

At the bottom of the Google Groups Page it give you the address for sending
mail to the group:

rubyonrails-talk@googlegroups.com

If you just want to search then just search. You don't have to have a
google account, although it isn't hard to get one.

···

On 5/2/07, zaphod <zaphod@s4r.de> wrote:

On Thu, 03 May 2007 00:09:46 +0900, Phillip Gawlowski wrote:

> zaphod wrote:
>> On Wed, 02 May 2007 23:42:09 +0900, Phillip Gawlowski wrote:
>>
>>> Secondly:
>>> The Rails groups can help you more with this question, I guess:
>>> Ruby on Rails — Community
>>
>> But what about people, who do not want to use ugly webforums or
>> even-more-ugly mailing lists which flood their mailboxes?
>
> What do you think is *this*?

A news group about "ruby"? As far as I understood your last posting,
comp.lang.ruby is not for discussing rails topics.

>> Do you know about a newsgroup where one can discuss rails topics?
>
> Very first entry on this website:
> Ruby on Rails — Community

The very first entry "general list" is not a news group but a google
group, for which I need a google account - or am I wrong and there is a
way to use them in my newsreader via nntp?

Ragards
Thomas

--
"Hey brother christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

zaphod wrote:

A news group about "ruby"? As far as I understood your last posting,
comp.lang.ruby is not for discussing rails topics.

On my end, it's a mailing list. For others, it is a webforum..

In general, you want to ask Rails questions in the Rails mailinglist, as your chances of getting an answer are higher by an order of magnitude.

The very first entry "general list" is not a news group but a google
group, for which I need a google account - or am I wrong and there is a
way to use them in my newsreader via nntp?

I have no clue. I use the email feature Google Groups provides. You'd be better of to seek for that answer in the Google Groups support.

···

--
Phillip "CynicalRyan" Gawlowski
http://cynicalryan.110mb.com/
http://clothred.rubyforge.org

Rule of Open-Source Programming #8:

Open-Source is not a panacea.

zaphod wrote:

A news group about "ruby"? As far as I understood your last posting,
comp.lang.ruby is not for discussing rails topics.

On my end, it's a mailing list. For others, it is a webforum..

And on my end it is a usenet newsgroup. But as far as I know, even google
makes a difference between usenet and mailinglists or google groups though
they have built various gateways into usenet. And usenet people definitly
do.

In general, you want to ask Rails questions in the Rails mailinglist, as
your chances of getting an answer are higher by an order of magnitude.

Yes. But I am searching for a usenet newsgroup for rails because without a
comfortable newsreader I would not read it anyway. But you are probably
the wrong person to ask.

The very first entry "general list" is not a news group but a google
group, for which I need a google account - or am I wrong and there is a
way to use them in my newsreader via nntp?

I have no clue. I use the email feature Google Groups provides. You'd be
better of to seek for that answer in the Google Groups support.

Again: I am not using google at all. But to get a clue, what I am talking
about: Usenet - Wikipedia

Regards
Thomas

···

On Thu, 03 May 2007 00:40:15 +0900, Phillip Gawlowski wrote: