Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
unintuitive language feature (exclamation functions)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Nick Brown, post: 4616338"] I was surprised to discover that the code astring.sub!(/hi/, 'bye') behaves subtly differently from astring = astring.sub(/hi/, 'bye') Intuitively, to me, these should be identical. Perhaps the documentation should make mention of this difference? A note about this unexpected behavior would have saved me a lot of frustration, and would likely do the same for many others new to Ruby. To be honest, I'm still trying to find out exactly why these do different things. The difference does not manifest itself with trivial cases in irb; rather it shows up when I'm getting a string from cgi, modifying it, then inserting it into a database. When using sub!, the database ends up containing the pre-sub'd value of astring, even though astring appears to contain the modified version when printed with a debug statement immediately preceding my database insert. I'm willing to except the criticism that my intuition is perverse in some way, but when I started writing in Ruby I was really hoping it would be a language one could use without having to understand how the C underneath it all worked (defeating part of the purpose of "high level" languages). So what do you think? Would warnings in the documentation on exclamation functions be useful or pointless? [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
unintuitive language feature (exclamation functions)
Top