Last active
October 13, 2017 16:52
-
-
Save just3ws/a032469e80ba9fc7b2a43784d085d769 to your computer and use it in GitHub Desktop.
Methods and stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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