Forum: Italian Ruby user group gsub and reg expressions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Stuart C. (Guest)
on 2008-11-16 19:33
After considerable time racking my brains on this one I am unsure on
where to go.

I am trying to replace some text with a the string 'local'

I am reading some data from an event description, therefore using a
regular expression to get only the data i want which is 'Logon Type: 2'

This works fine but when I add gsub to the expression in an attempt to
replace 'Logon Type: 2' with "local" I get the following error:

C:/Documents and Settings/sc/Desktop/stutest.rb:116:in `gsub': wrong
argumen
t type Array (expected Regexp) (TypeError)


Also my code

#{event.description.gsub([/Logon Type:\t2/], 'Local')}")

Thanks in advance
Duilio R. (Guest)
on 2008-11-17 20:15
Stuart C. wrote:
> After considerable time racking my brains on this one I am unsure on
> where to go.
>
> I am trying to replace some text with a the string 'local'
>
> I am reading some data from an event description, therefore using a
> regular expression to get only the data i want which is 'Logon Type: 2'
>
> This works fine but when I add gsub to the expression in an attempt to
> replace 'Logon Type: 2' with "local" I get the following error:
>
> C:/Documents and Settings/sc/Desktop/stutest.rb:116:in `gsub': wrong
> argumen
> t type Array (expected Regexp) (TypeError)
>
>
> Also my code
>
> #{event.description.gsub([/Logon Type:\t2/], 'Local')}")

mmm

[/Logon Type:\t2/] IS an Array

/Logon Type:\t2/ is a Regexp

take off the square brackets  ;)
and you have:

("#{event.description.gsub(/Logon Type:\t2/, 'Local')}")

>
> Thanks in advance

Not at all

Duilio R.
This topic is locked and can not be replied to.