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
| service: crysto | |
| image: wyodeb/crysto | |
| servers: | |
| web: | |
| hosts: | |
| - 188...... | |
| job: | |
| hosts: | |
| - 188...... |
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 Magician | |
| def method_missing(name, *args) | |
| puts "You tried to call #{name} with these arguments: #{args.join(', ')}" | |
| end | |
| end | |
| magician = Magician.new | |
| magician.cast_spell("fireball", "enemy") # You tried to call cast_spell with these arguments: fireball, enemy |
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 MyClass | |
| def self.create_methods(methods) | |
| methods.each do |method_name| | |
| define_method(method_name) do | |
| "This is method #{method_name}" | |
| end | |
| end | |
| end | |
| create_methods([:method1, :method2]) |
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 DynamicProxy | |
| def initialize(subject) | |
| @subject = subject | |
| end | |
| def method_missing(method_name, *args, &block) | |
| if @subject.respond_to?(method_name) | |
| @subject.send(method_name, *args, &block) | |
| else | |
| super |
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 FakeNumber | |
| def initialize(value) | |
| @value = value | |
| end | |
| def +(other) | |
| @value + other.to_i | |
| end | |
| def to_i |
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
| module Enumerable | |
| def my_map | |
| result = [] | |
| each { |item| result << yield(item) } | |
| result | |
| end | |
| end |
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
| sum = lambda {|a, b| a + b } | |
| puts sum.call(2, 3) #=> 5 |
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
| # Example 1: Monkey patching the String class | |
| class String | |
| def to_b | |
| return true if self == "true" | |
| return false if self == "false" | |
| raise ArgumentError.new("invalid value for Boolean: #{self}") | |
| end | |
| end | |
| # Usage: |
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 UsersController < ApplicationController | |
| def index | |
| @users = UserFilterService.new(params[:query]).filter | |
| end | |
| end |
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
| require: rubocop-rails # If you have rubocop-rails installed | |
| AllCops: | |
| TargetRubyVersion: 3.2.0 # Do not forget to put your Ruby version here | |
| Exclude: | |
| - 'db/**/*' | |
| - 'bin/*' | |
| - 'config/**/*' | |
| - 'lib/**/*' | |
| - 'spec/**/*' | |
| - 'Gemfile' |
NewerOlder