Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ezkl/1525397 to your computer and use it in GitHub Desktop.

Select an option

Save ezkl/1525397 to your computer and use it in GitHub Desktop.

Revisions

  1. ezkl revised this gist Dec 27, 2011. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions local_var_overwrite_warning.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,9 @@
    # http://stackoverflow.com/questions/8647320/ruby-use-condition-result-in-condition-block/8647391#8647391
    prefix = nil
    if /(?<prefix>.+)_path/ =~ "home_path" # !> named capture conflicts a local variable - prefix
    puts prefix
    # Much more realistic context.
    def extract_prefix_from_path(path)
    /(?<prefix>.+)_path/ =~ path.to_s ? prefix : false
    end

    path = extract_prefix_from_path("homepath")
    puts path #=> false

    puts extract_prefix_from_path("home_path") #=> home
  2. @JoshCheek JoshCheek created this gist Dec 27, 2011.
    5 changes: 5 additions & 0 deletions local_var_overwrite_warning.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    # http://stackoverflow.com/questions/8647320/ruby-use-condition-result-in-condition-block/8647391#8647391
    prefix = nil
    if /(?<prefix>.+)_path/ =~ "home_path" # !> named capture conflicts a local variable - prefix
    puts prefix
    end