Skip to content

Instantly share code, notes, and snippets.

Tobias Bühlmann tbuehlmann

  • Germany
Block or report user

Report or block tbuehlmann

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View some_file.rb
def some_method
some_variable = 42
yield some_variable
end
some_method do |that_variable|
puts that_variable
end
View output.txt
$ bundle exec ruby spec.rb 1 ↵
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using bundler 1.17.3
Using diff-lcs 1.3
Using rspec-support 3.8.0
Using rspec-core 3.8.0
Using rspec-expectations 3.8.2
Using rspec-mocks 3.8.0
View owner_reservations_controller.rb
# app/controllers/owner/reservations_controller.rb
class Owner::ReservationsController < ApplicationController
def create
#
end
end
View a.rb
# a.rb
require_relative 'a/b'
module A
end
View retry_jobs_without_exception.rb
# lib/sidekiq/middleware/server/retry_jobs_without_exception.rb
module Sidekiq
RetryWithoutException = Class.new(StandardError)
module Middleware
module Server
class RetryJobsWithoutException < RetryJobs
def call(worker, msg, queue)
begin
View some_model.rb
class SomeModel < ApplicationRecord
after_initialize do
if new_record?
{some_attribute: 'default value'}.each do |attribute, value|
public_send("#{attribute}=", value) unless public_send(attribute)
end
end
end
end
View test_response.rb
# frozen_string_literal: true
require "action_dispatch/testing/request_encoder"
module ActionDispatch
# Integration test methods such as ActionDispatch::Integration::Session#get
# and ActionDispatch::Integration::Session#post return objects of class
# TestResponse, which represent the HTTP response results of the requested
# controller actions.
#
View base_audits_controller.rb
class BaseAuditsController < ApplicationController
def self.inherited(other)
other.class_eval do
resource_name = controller_path.split('/').first.singularize
define_method("set_#{resource_name}") do
resource = organization.public_send(resource_name.pluralize).find(params["#{resource_name}_id"])
instance_variable_set("@#{resource_name}", resource)
end
View console.rb
Listen.to('app/controllers') do |modified, added, removed|
puts "modified absolute path: #{modified}"
puts "added absolute path: #{added}"
puts "removed absolute path: #{removed}"
end.start
View implicit_casting.rb
'foo' + 42 # => TypeError: no implicit conversion of Integer into String
class Integer
def to_str
to_s
end
end
'foo' + 42 # => 'foo42'
You can’t perform that action at this time.