Skip to content

Instantly share code, notes, and snippets.

@Morozzzko
Created April 6, 2022 14:39
Show Gist options
  • Select an option

  • Save Morozzzko/1e65d18e6f2ae27c5fb0e5980654e013 to your computer and use it in GitHub Desktop.

Select an option

Save Morozzzko/1e65d18e6f2ae27c5fb0e5980654e013 to your computer and use it in GitHub Desktop.
Method missing example
def method_missing(raw_name, *args, **kwargs)
name = raw_name.to_s
match = name.match(/say_(?<text>[\w_]+)_to_(?<addressee>[\w_]+)/)
if match
text = match['text'].gsub('_', ' ')
addressee = match['addressee'].split('_').map(&:capitalize).join(' ')
puts "Message to #{addressee}: #{text}"
return
else
super
end
end
say_hello_to_yaroslav
say_privet_poydem_v_restoran_krasiviy_muzchina_to_moy_lyubimyi_yaroslav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment