What's the difference between these two snippets of ruby?

Sorry I couldn't help the line wrapping. Thanks in advance.

parent_path =
File.expand_path(config['parent'],
File.dirname(yaml_path)).gsub('${project_dir}',
PROJECT_ROOT)

config['parent'].gsub!("${project_dir}", PROJECT_ROOT)
parent_path = File.expand_path(config['parent'],
File.dirname(yaml_path))

···

--
Posted via http://www.ruby-forum.com/.

The second version modifies config['parent']

If you want the second version, which is much easier to understand, imo. But
don't want the side effect of changing the config hash, then use gsub
without the bang, and assign it to a local variable:

parent = config['parent'].gsub("${project_dir}", PROJECT_ROOT)
parent_path = File.expand_path( parent , File.dirname(yaml_path) )

···

On Sat, Jan 15, 2011 at 8:06 AM, Mr. Bill <mrbillhaxor@yahoo.com> wrote:

Sorry I couldn't help the line wrapping. Thanks in advance.

parent_path =
File.expand_path(config['parent'],
File.dirname(yaml_path)).gsub('${project_dir}',
PROJECT_ROOT)

config['parent'].gsub!("${project_dir}", PROJECT_ROOT)
parent_path = File.expand_path(config['parent'],
File.dirname(yaml_path))

--
Posted via http://www.ruby-forum.com/.

Got it. Thank you much.

Josh Cheek wrote in post #975146:

···

On Sat, Jan 15, 2011 at 8:06 AM, Mr. Bill <mrbillhaxor@yahoo.com> wrote:

File.dirname(yaml_path))

--
Posted via http://www.ruby-forum.com/.

The second version modifies config['parent']

If you want the second version, which is much easier to understand, imo.
But
don't want the side effect of changing the config hash, then use gsub
without the bang, and assign it to a local variable:

parent = config['parent'].gsub("${project_dir}", PROJECT_ROOT)
parent_path = File.expand_path( parent , File.dirname(yaml_path) )

--
Posted via http://www.ruby-forum.com/.