Last active
September 8, 2018 21:53
-
-
Save mehdi-farsi/a66dbb1e8416370245a4610e14ce7ff2 to your computer and use it in GitHub Desktop.
dummy_rails_app
This file contains 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
# lib/core_ext/hash.rb | |
class Hash | |
# monkey-patch to temporarily | |
# disabling the MyLib#print_config output | |
def to_json | |
'' | |
end | |
end |
This file contains 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
# lib/my_lib.rb | |
class MyLib | |
attr_accessor :config | |
def initialize | |
config = {} | |
yield(config) if block_given? | |
end | |
def print_config | |
"config: #{config.to_json}" # <= Monkey-patch applied here | |
end | |
end |
This file contains 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
# app/controllers/products_controller.rb | |
class ProductsController < ApplicationController | |
def index | |
@products = { | |
products: [ | |
# list of products | |
] | |
} | |
render json: @products # <= Side-effect of the monkey-patch | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment