Skip to content

Instantly share code, notes, and snippets.

View pocke's full-sized avatar
⌨️
Pocke is typing...

Masataka Pocke Kuwabara pocke

⌨️
Pocke is typing...
View GitHub Profile
class Binding
def return_if(name)
eval "return #{name}" if local_variable_get(name)
end
end
def foo(v)
binding.return_if(:v)
'v is nil'
end
@pocke
pocke / a.rb
Created February 25, 2017 13:58
require 'ripper'
require 'pp'
def x(&blk)
blk.call([1,2,3,4,5])
end
code = 'x{|(x, *a, y)| p x; p a; p y }'
eval code
pp Ripper.sexp(code)
:grinning: 😀
:grin: 😁
:joy: 😂
:rofl: 🤣
:rolling_on_the_floor_laughing: 🤣
:smiley: 😃
:smile: 😄
:sweat_smile: 😅
:laughing: 😆
:satisfied: 😆
script/test
===> Bundling...
Please export OCTOKIT_TEST_GITHUB_LOGIN
Please export OCTOKIT_TEST_GITHUB_PASSWORD
Please export OCTOKIT_TEST_GITHUB_TOKEN
Please export OCTOKIT_TEST_GITHUB_CLIENT_ID
Please export OCTOKIT_TEST_GITHUB_CLIENT_SECRET
===> Running specs...
[DEPRECATION] `last_comment` is deprecated. Please use `last_description` instead.
/usr/bin/ruby -I/home/pocke/.gem/ruby/2.4.0/gems/rspec-core-3.0.4/lib:/home/pocke/.gem/ruby/2.4.0/gems/rspec-support-3.0.4/lib -S /home/pocke/.gem/ruby/2.4.0/gems/rspec-core-3.0.4/exe/rspec ./spec/octokit/client/authorizations_spec.rb ./spec/octokit/client/commit_comments_spec.rb ./spec/octokit/client/commits_spec.rb ./spec/octokit/client/contents_spec.rb ./spec/octokit/client/deployments_spec.rb ./spec/octokit/client/downloads_spec.rb ./spec/octokit/client/emojis_spec.rb ./spec/octokit/client/events_spec.rb ./spec/octokit/client/feeds_spec.rb ./spec/octokit/client/gists_spec.rb ./spec/octokit/client/gitignore_spec.rb ./spec/octokit/client/hooks_spec.rb ./spec/octok
class NilClass
def if
self
end
def else
yield self
end
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def foo
return 1
42
# ^^ Lint/UnreachableCode: Unreachable code detected.
end
diff --git a/lib/rubocop/cop/rails/blank.rb b/lib/rubocop/cop/rails/blank.rb
index 119eed2b..ae2a8e36 100644
--- a/lib/rubocop/cop/rails/blank.rb
+++ b/lib/rubocop/cop/rails/blank.rb
@@ -52,8 +52,7 @@ module RuboCop
(send $_ :!)
(send $_ :nil?)
(send $_ :== (:nil))
- (send nil $_)
- (send (:nil) :== $_)
diff --git a/lib/rubocop/node_pattern.rb b/lib/rubocop/node_pattern.rb
index 10da0350..9638590f 100644
--- a/lib/rubocop/node_pattern.rb
+++ b/lib/rubocop/node_pattern.rb
@@ -98,7 +98,7 @@ module RuboCop
# @private
# Builds Ruby code which implements a pattern
class Compiler
- SYMBOL = %r{:(?:[\w+@*/?!<>=~|%^-]+|\[\]=?)}
+ SYMBOL = %r{:(?:[\w+@*/?!<>=~|%^$-]+|\[\]=?)}
@pocke
pocke / atasgn.rb
Created November 3, 2017 14:08
Automatically assign arguments to instance variables
module Atasgn
def atasgn(method_name)
parameters = instance_method(method_name).parameters
if parameters.any?{|type, _name| type == :opt || type == :key}
raise 'Can not use a parameter with default value'
end
prepend(Module.new do
eval <<~RUBY
def #{method_name}(#{parameters.map do |type, name|