Skip to content

Instantly share code, notes, and snippets.

@just3ws
Last active October 13, 2017 16:52
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 just3ws/a032469e80ba9fc7b2a43784d085d769 to your computer and use it in GitHub Desktop.
Save just3ws/a032469e80ba9fc7b2a43784d085d769 to your computer and use it in GitHub Desktop.
Methods and stuff
class Foo
attr_reader :env
def initialize
@env = 'staging' # Rail.env
end
def bar
warninger(biz: 123, buz: 'Hello', baz: Object.new)
end
def warninger(**kargs)
return unless env == 'staging'
klass = self.class.name
method = caller_locations(1,1)[0].label
arguments = kargs
.flatten
.each_slice(2)
.map { |attr,val| [attr,val.inspect].join(': ') }.join(', ')
message = "[#{env}][AUTOMATED EMAIL WARNING] #{klass}##{method} called with arguments: #{arguments}"
puts message
end
end
Foo.new.bar
# In the same directory as this file...
#
# ```
#
# irb -I./ -r methods
#
# ```
#
# or
#
# ```
#
# ruby methods.rb
#
# ````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment