Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezkl/1525397 to your computer and use it in GitHub Desktop.
Save ezkl/1525397 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment