Drunk Proxy

Краен срок
14.12.2016 23:59

Срокът за предаване на решения е отминал

Drunk Proxy

Дефинирайте клас DrunkProxy, чийто конструктор приема като единствен аргумент списък от обекти. Инстанцията на класа трябва да отговаря на всички методи, на които отговарят подадените обекти в конструктора. Възможно е няколко обекта да могат да отговорят на един метод (например '123'.length и [1, 2].length). Ако проксито може да отговори на даден метод, то връща списък с резултатите от всички обекти, които са кандидати за отговор (редът в списъка на резултатите трябва да съответства на реда на подаване на обектите при инициализация).

Примери:

proxy = DrunkProxy.new [-42, 'foo', 'bar baz', [2, 3, 5, 8]]
proxy.reverse # => ["oof", "zab rab", [8, 5, 3, 2]]
proxy.abs     # => [42]
proxy.length  # => [3, 7, 4]
# ----------------------------------------------------------
proxy = DrunkProxy.new ['foo', [24], {x: 2}]
proxy.class   # => [String, Array, Hash]

Бележки:

  • Ако няма обект, който да отговори на дадения метод, вдигнете NoMethodError изключение.
  • Постарайте се да прихванете всички методи, на които подадените обекти могат да отговорят. Изключение правят !, ==, !=, __send__, equal?, instance_veal, instance_exec, __id__ и __binding__
  • Няма да подаваме блокове на методите в тестовете. Тоест, не се тревожете за нещо подобно на:
proxy = DrunkProxy.new [[2, 3, 5, 8], {a: 1, b: 2, c: 3}]
proxy.select(&:odd?)
proxy.select { |x| x > 42 }

Примерни тестове

Написали сме примерни тестове, които може да намерите в хранилището с домашните.

Решения

Здравко Петров
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Здравко Петров
class NullObject
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval|object_id/ }
end
class DrunkProxy < NullObject
def initialize(*objects_arr)
@objects = []
objects_arr.each do |index|
index.each do |value|
@objects << value
end
end
end
def method_missing(method_name, *arguments, &block)
has_method(method_name)
end
def has_method(name)
@check = false;
@return_value = []
@objects.each do |value|
if value.methods.include?(name.to_sym)
@return_value << value.send(name)
@check = true;
end
end
raise NoMethodError.new("No method such as \"#{name}\" found!") if !@check
@return_value
end
def self.const_missing(name)
::Object.const_get(name)
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
     ArgumentError:
       wrong number of arguments (given 0, expected 1)
     # /tmp/d20161215-15620-sofe0a/solution.rb:25:in `is_a?'
     # /tmp/d20161215-15620-sofe0a/solution.rb:25:in `block in has_method'
     # /tmp/d20161215-15620-sofe0a/solution.rb:23:in `each'
     # /tmp/d20161215-15620-sofe0a/solution.rb:23:in `has_method'
     # /tmp/d20161215-15620-sofe0a/solution.rb:17:in `method_missing'
     # /tmp/d20161215-15620-sofe0a/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00668 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-sofe0a/spec.rb:14 # DrunkProxy proxies most of the methods
Добрин Цветков
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Добрин Цветков
class DrunkProxy
attr_accessor :objects, :methods_list
def initialize(array)
@objects = array
basic_methods = BasicObject.instance_methods
@methods_list = objects.map do |object|
object.methods
end.reduce(:|) - basic_methods
methods_macro
end
def methods_macro
@methods_list.each do |method_name|
DrunkProxy.send(:define_method, method_name) do
objects.select do |object|
object.respond_to?(method_name)
end.map { |object| object.send(method_name) }
end
end
end
end
.FF.

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
     ArgumentError:
       wrong number of arguments (given 1, expected 0)
     # /tmp/d20161215-15620-1jbm280/solution.rb:14:in `block (2 levels) in methods_macro'
     # /tmp/d20161215-15620-1jbm280/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) DrunkProxy raises error when calling missing methods
     Failure/Error: expect { DrunkProxy.new(['string']).abs }.to raise_error(NoMethodError)
       expected NoMethodError but nothing was raised
     # /tmp/d20161215-15620-1jbm280/spec.rb:25:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.03813 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20161215-15620-1jbm280/spec.rb:14 # DrunkProxy proxies most of the methods
rspec /tmp/d20161215-15620-1jbm280/spec.rb:23 # DrunkProxy raises error when calling missing methods
Даниела Русева
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Даниела Русева
class DrunkProxy
EXCEPTIONS = [:!, :==, :!=, :__send__, :equal?, :instance_veal, :instance_exec, :__id__, :__binding__]
def initialize(objects)
@objects = objects
@objects.each do |n|
(n.methods - EXCEPTIONS).each do |m|
define_methods(m.to_s)
end
end
end
def define_methods(name)
DrunkProxy.instance_eval do
define_method(name) do
result = @objects.select { |n| n.respond_to?(name) }
raise NoMethodError if result.empty?
result.map { |n| n.send(name) }
end
end
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
     ArgumentError:
       wrong number of arguments (given 1, expected 0)
     # /tmp/d20161215-15620-16epimk/solution.rb:14:in `block (2 levels) in define_methods'
     # /tmp/d20161215-15620-16epimk/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.01327 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-16epimk/spec.rb:14 # DrunkProxy proxies most of the methods
Божидар Михайлов
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Божидар Михайлов
class DrunkProxy < BasicObject
def initialize(objs)
@objs = objs
end
private
def method_missing(method, *args)
responding = @objs.select { |obj| obj.respond_to? method }
raise NoMethodError unless responding
responding.map { |obj| obj.send(method, *args) }
end
end
..FF

Failures:

  1) DrunkProxy raises error when calling missing methods
     Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
       expected NoMethodError but nothing was raised
     # /tmp/d20161215-15620-993714/spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) DrunkProxy raises error when calling private methods
     Failure/Error: expect { proxy.private_method }.to raise_error(NoMethodError)
       expected NoMethodError but nothing was raised
     # /tmp/d20161215-15620-993714/spec.rb:32:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.0042 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20161215-15620-993714/spec.rb:23 # DrunkProxy raises error when calling missing methods
rspec /tmp/d20161215-15620-993714/spec.rb:28 # DrunkProxy raises error when calling private methods
Христина Тодорова
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Христина Тодорова
class DrunkProxy
METHODS_TO_SKIP = %w(! == != __send__ equal? instance_veal instance_exec __id__ __binding__)
def initialize(array)
@list = array
@list.each do |element|
metohds_to_define = element.methods
metohds_to_define.each do |m|
add_method(m) if element.method(m).arity == 0 && !METHODS_TO_SKIP.include?(m)
end
end
end
def add_method(method)
block = Proc.new do
result = []
@list.each{ |x| result << x.send(method) if x.respond_to?(method) }
result
end
self.send(:define_singleton_method, method, block)
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
       
       expected: [true, false]
            got: false
       
       (compared using ==)
     # /tmp/d20161215-15620-nghh0x/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00951 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-nghh0x/spec.rb:14 # DrunkProxy proxies most of the methods
Лазар Дилов
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Лазар Дилов
# Inherits BasicObject
class DrunkProxy < BasicObject
def initialize(args)
@arg = args
end
def method_missing(name)
super unless @arg.any? { |x| x.respond_to?(name) }
@arg.select { |v| v.respond_to?(name) }.map { |x| x.public_send(name) }
end
def respond_to_missing?(name)
super unless @arg.any? { |x| x.respond_to?(name) }
@arg.select { |v| v.respond_to?(name) }.map { |x| x.public_send(name) }
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
     ArgumentError:
       wrong number of arguments (given 2, expected 1)
     # /tmp/d20161215-15620-btwz4v/solution.rb:7:in `method_missing'
     # /tmp/d20161215-15620-btwz4v/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00432 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-btwz4v/spec.rb:14 # DrunkProxy proxies most of the methods
Петко Митков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Петко Митков
class DrunkProxy
INSTANCE_METHODS = [:'=!', :'==', :'!=',
:'__send__', :'equal?', :'instance_eval',
:'instance_exec', :'__id__', :'__binding__']
(instance_methods - INSTANCE_METHODS).each { |m| undef_method m }
def initialize(argz)
@parameters = *argz
end
private
def method_missing(method, *argz, &block)
raise NoMethodError if @parameters.none? { |p| p.respond_to?(method) }
@parameters.select { |p| p.respond_to?(method) }.map { |p| p.send(method, *argz, &block) }
end
end
/tmp/d20161215-15620-1tmpzpj/solution.rb:6: warning: undefining `object_id' may cause serious problems
....

Finished in 0.0042 seconds
4 examples, 0 failures
Никола Жишев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Жишев
class DrunkProxy < BasicObject
attr_reader :objects
def initialize(objects)
@objects = objects
end
def method_missing(name, *args)
mapped = objects.select { |o| o.respond_to? name }
.map { |o| o.send name, *args }
mapped.empty? ? super : mapped
end
end
....

Finished in 0.00427 seconds
4 examples, 0 failures
Ралица Дарджонова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Дарджонова
class DrunkProxy
def initialize(list_with_objects)
@list = list_with_objects
undefine_methods
end
def method_missing(method_name, *args)
result_list = []
@list.each do |object|
if object.respond_to? method_name
result_list << object.send(method_name, *args)
end
end
if result_list.empty?
raise NoMethodError
else
result_list
end
end
def undefine_methods()
exception = [
:!,
:==,
:!=,
:__send__,
:equal?,
:instance_eval,
:instance_exec,
:__id__,
:__binding__,
:method_missing,
:undefine_methods,
:object_id
]
methods = self.methods
methods.each do |method|
if !exception.include? method
self.instance_eval("undef :#{method}")
end
end
end
end
....

Finished in 0.01207 seconds
4 examples, 0 failures
Мариян Асенов
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Мариян Асенов
class DrunkProxy
def initialize(objects)
@list_of_objects = objects
end
methods.each do |name|
define_method name do
@list_of_objects.map { |object| object.send(name) }
end
end
def method_missing(method_name)
selected_objects = @list_of_objects.select { |object| object.methods.include?(method_name) }
raise NoMethodError if selected_objects.empty?
selected_objects.map { |object| object.send(method_name) }
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
     ArgumentError:
       wrong number of arguments (given 1, expected 0)
     # /tmp/d20161215-15620-3za109/solution.rb:7:in `block (2 levels) in <class:DrunkProxy>'
     # /tmp/d20161215-15620-3za109/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00626 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-3za109/spec.rb:14 # DrunkProxy proxies most of the methods
Георги Иванов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Иванов
class DrunkProxy < BasicObject
def initialize(args)
@array = args
end
def method_missing(method, *args)
responding = @array.select { |element| element.respond_to? method }
::Kernel.raise ::NoMethodError if responding.empty?
responding.map { |element| element.send(method, *args) }
end
end
....

Finished in 0.00423 seconds
4 examples, 0 failures
Делян Лафчиев
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Делян Лафчиев
class DrunkProxy
instance_methods.each { |method| undef_method method unless method =~ /(^__|^send$|^object_id$)/ }
def initialize(object_array)
@objs = object_array
end
def method_missing(method, *args)
responding_objs = @objs.select { |obj| obj.respond_to? method }
responding_objs.map { |obj| obj.__send__ method, *args }
end
end
..FF

Failures:

  1) DrunkProxy raises error when calling missing methods
     Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
       expected NoMethodError but nothing was raised
     # /tmp/d20161215-15620-1xmam7c/spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) DrunkProxy raises error when calling private methods
     Failure/Error: expect { proxy.private_method }.to raise_error(NoMethodError)
       expected NoMethodError but nothing was raised
     # /tmp/d20161215-15620-1xmam7c/spec.rb:32:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00472 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20161215-15620-1xmam7c/spec.rb:23 # DrunkProxy raises error when calling missing methods
rspec /tmp/d20161215-15620-1xmam7c/spec.rb:28 # DrunkProxy raises error when calling private methods
Георги Карапетров
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Георги Карапетров
class DrunkProxy
def initialize(list)
@list = list
end
def method_missing(method_name, *args)
results = @list.map { |object| object.send(method_name, *args) if object.respond_to? method_name }
results.compact!
raise NoMethodError if results.empty?
results
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.class).to eq [string.class, array.class]
       
       expected: [String, Array]
            got: DrunkProxy
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -[String, Array]
       +DrunkProxy
     # /tmp/d20161215-15620-xn8amt/spec.rb:19:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00474 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-xn8amt/spec.rb:14 # DrunkProxy proxies most of the methods
Милен Дончев
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Милен Дончев
module Methods
end
class DrunkProxy
include Methods
attr_reader :list
def initialize(list)
@list = list
append_methods
end
def append_methods
hash = Hash.new
@list.each do |item|
item.methods.map { |method| hash[method] = 1 }
end
fixed = hash.keys - [:!, :==, :!=, :__send__, :equal?, :instance_veal, :instance_exec, :__id__, :__binding__]
hash.each do |key,_|
if (fixed.include? key)
Methods.send(:define_method, key) do
@list.select { |x| x.respond_to? key }
.map{ |x| x.method(key).call() }
end
end
end
end
end
.FF.

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
     ArgumentError:
       wrong number of arguments (given 1, expected 0)
     # /tmp/d20161215-15620-nek98a/solution.rb:24:in `block (2 levels) in append_methods'
     # /tmp/d20161215-15620-nek98a/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) DrunkProxy raises error when calling missing methods
     Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
       expected NoMethodError but nothing was raised
     # /tmp/d20161215-15620-nek98a/spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.01144 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20161215-15620-nek98a/spec.rb:14 # DrunkProxy proxies most of the methods
rspec /tmp/d20161215-15620-nek98a/spec.rb:23 # DrunkProxy raises error when calling missing methods
Виктор Маринов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Маринов
class DrunkProxy < BasicObject
def self.const_missing(name)
::Object.const_get(name)
end
def initialize(args)
@objects = args
end
def method_missing(method, *args, &block)
results = @objects
.select { |obj| obj.respond_to? method }
.map { |obj| obj.send method, *args }
if results.empty?
Kernel::raise NoMethodError, "No method #{method} for any of the objects."
end
results
end
end
....

Finished in 0.00418 seconds
4 examples, 0 failures
Исмаил Алиджиков
  • Некоректно
  • 1 успешни тест(а)
  • 3 неуспешни тест(а)
Исмаил Алиджиков
class DrunkProxy < BasicObject
def initialize(args)
@objects = args
end
def method_missing(name, *args, &block)
@objects
.select { |obj| obj.respond_to? name }
.map { |obj| obj.send(name) }
end
end
.FFF

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
     ArgumentError:
       wrong number of arguments (given 0, expected 1)
     # /tmp/d20161215-15620-1thwcgc/solution.rb:10:in `is_a?'
     # /tmp/d20161215-15620-1thwcgc/solution.rb:10:in `block in method_missing'
     # /tmp/d20161215-15620-1thwcgc/solution.rb:10:in `map'
     # /tmp/d20161215-15620-1thwcgc/solution.rb:10:in `method_missing'
     # /tmp/d20161215-15620-1thwcgc/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) DrunkProxy raises error when calling missing methods
     Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
       expected NoMethodError but nothing was raised
     # /tmp/d20161215-15620-1thwcgc/spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  3) DrunkProxy raises error when calling private methods
     Failure/Error: expect { proxy.private_method }.to raise_error(NoMethodError)
       expected NoMethodError but nothing was raised
     # /tmp/d20161215-15620-1thwcgc/spec.rb:32:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00422 seconds
4 examples, 3 failures

Failed examples:

rspec /tmp/d20161215-15620-1thwcgc/spec.rb:14 # DrunkProxy proxies most of the methods
rspec /tmp/d20161215-15620-1thwcgc/spec.rb:23 # DrunkProxy raises error when calling missing methods
rspec /tmp/d20161215-15620-1thwcgc/spec.rb:28 # DrunkProxy raises error when calling private methods
Антон Сотиров
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Антон Сотиров
class DrunkProxy
def initialize(arr=[])
@array = arr
end
def method_missing(m,*args)
output = []
@array.each do |x|
output.push(x.send(m,*args)) if x.methods.include?(m)
end
raise NoMethodError if output.empty?
output
end
def class()
output = []
@array.each do |x|
output.push(x.class)
end
raise NoMethodError if output.empty?
output
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
       
       expected: [true, false]
            got: false
       
       (compared using ==)
     # /tmp/d20161215-15620-uadikd/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00631 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-uadikd/spec.rb:14 # DrunkProxy proxies most of the methods
Йордан Иванов
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Йордан Иванов
class DrunkProxy < BasicObject
attr_accessor :arguments
def initialize arguments
@arguments = arguments
end
def method_missing(name, *args, &block)
none_responding = true
array = []
@arguments.each do |object|
array << object.send(name,*args) if object.respond_to? name
end
array.empty? ? (throw NoMethodError) : array
end
end
..FF

Failures:

  1) DrunkProxy raises error when calling missing methods
     Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
       expected NoMethodError, got #<NameError: uninitialized constant DrunkProxy::NoMethodError> with backtrace:
         # /tmp/d20161215-15620-1sr8itn/solution.rb:13:in `method_missing'
         # /tmp/d20161215-15620-1sr8itn/spec.rb:24:in `block (3 levels) in <top (required)>'
         # /tmp/d20161215-15620-1sr8itn/spec.rb:24:in `block (2 levels) in <top (required)>'
         # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
         # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
     # /tmp/d20161215-15620-1sr8itn/spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) DrunkProxy raises error when calling private methods
     Failure/Error: expect { proxy.private_method }.to raise_error(NoMethodError)
       expected NoMethodError, got #<NameError: uninitialized constant DrunkProxy::NoMethodError> with backtrace:
         # /tmp/d20161215-15620-1sr8itn/solution.rb:13:in `method_missing'
         # /tmp/d20161215-15620-1sr8itn/spec.rb:32:in `block (3 levels) in <top (required)>'
         # /tmp/d20161215-15620-1sr8itn/spec.rb:32:in `block (2 levels) in <top (required)>'
         # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
         # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
     # /tmp/d20161215-15620-1sr8itn/spec.rb:32:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00557 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20161215-15620-1sr8itn/spec.rb:23 # DrunkProxy raises error when calling missing methods
rspec /tmp/d20161215-15620-1sr8itn/spec.rb:28 # DrunkProxy raises error when calling private methods
Христо Кирилов
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Христо Кирилов
class DrunkProxy < BasicObject
def initialize(args)
@obj = args
end
def method_missing(name, *args, &block)
result = @obj.select { |i| i.respond_to? name }.map { |i| i.send name }
result.empty? ? super : result
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
     ArgumentError:
       wrong number of arguments (given 0, expected 1)
     # /tmp/d20161215-15620-117url6/solution.rb:7:in `is_a?'
     # /tmp/d20161215-15620-117url6/solution.rb:7:in `block in method_missing'
     # /tmp/d20161215-15620-117url6/solution.rb:7:in `map'
     # /tmp/d20161215-15620-117url6/solution.rb:7:in `method_missing'
     # /tmp/d20161215-15620-117url6/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00425 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-117url6/spec.rb:14 # DrunkProxy proxies most of the methods
Елеонора Кайкова
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Елеонора Кайкова
class DrunkProxy
def initialize(array)
@array = array
end
def method_missing(method_name)
answer = []
@array.each do |item|
answer << item.public_send(method_name) if item.class.instance_methods.include? method_name
end
answer == [] ? (raise NoMethodError) : answer
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.class).to eq [string.class, array.class]
       
       expected: [String, Array]
            got: DrunkProxy
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -[String, Array]
       +DrunkProxy
     # /tmp/d20161215-15620-y90szz/spec.rb:19:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00684 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-y90szz/spec.rb:14 # DrunkProxy proxies most of the methods
Стамен Драгоев
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Стамен Драгоев
class DrunkProxy
def initialize(args)
@storage=args
instance_eval("undef #{:instance_of?}")
instance_eval("undef #{:public_send}")
instance_eval("undef #{:instance_variable_get}")
instance_eval("undef #{:instance_variable_set}")
instance_eval("undef #{:instance_variable_defined?}")
instance_eval("undef #{:remove_instance_variable}")
instance_eval("undef #{:private_methods}")
instance_eval("undef #{:kind_of?}")
instance_eval("undef #{:instance_variables}")
instance_eval("undef #{:tap}")
instance_eval("undef #{:is_a?}")
instance_eval("undef #{:extend}")
instance_eval("undef #{:to_enum}")
instance_eval("undef #{:enum_for}")
instance_eval("undef #{:<=>}")
instance_eval("undef #{:===}")
instance_eval("undef #{:=~}")
instance_eval("undef #{:!~}")
instance_eval("undef #{:eql?}")
instance_eval("undef #{:respond_to?}")
instance_eval("undef #{:freeze}")
instance_eval("undef #{:inspect}")
instance_eval("undef #{:display}")
instance_eval("undef #{:send}")
instance_eval("undef #{:to_s}")
instance_eval("undef #{:method}")
instance_eval("undef #{:public_method}")
instance_eval("undef #{:singleton_method}")
instance_eval("undef #{:define_singleton_method}")
instance_eval("undef #{:nil?}")
instance_eval("undef #{:hash}")
instance_eval("undef #{:class}")
instance_eval("undef #{:singleton_class}")
instance_eval("undef #{:clone}")
instance_eval("undef #{:dup}")
instance_eval("undef #{:itself}")
instance_eval("undef #{:taint}")
instance_eval("undef #{:tainted?}")
instance_eval("undef #{:untaint}")
instance_eval("undef #{:untrust}")
instance_eval("undef #{:trust}")
instance_eval("undef #{:untrusted?}")
instance_eval("undef #{:protected_methods}")
instance_eval("undef #{:frozen?}")
instance_eval("undef #{:public_methods}")
instance_eval("undef #{:singleton_methods}")
end
def method_missing(name,*args,&block)
raise NoMethodError unless @storage.any? { |e| e.respond_to?(name) }
@storage.select do |e|
e.respond_to?(name)
end.map { |e| e.send(name) }
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
     ArgumentError:
       wrong number of arguments (given 0, expected 1)
     # /tmp/d20161215-15620-1b2z5yd/solution.rb:56:in `is_a?'
     # /tmp/d20161215-15620-1b2z5yd/solution.rb:56:in `block in method_missing'
     # /tmp/d20161215-15620-1b2z5yd/solution.rb:56:in `map'
     # /tmp/d20161215-15620-1b2z5yd/solution.rb:56:in `method_missing'
     # /tmp/d20161215-15620-1b2z5yd/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00897 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-1b2z5yd/spec.rb:14 # DrunkProxy proxies most of the methods
Теодора Петкова
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Теодора Петкова
class DrunkProxy
def initialize(objects)
@objects = objects
end
def method_missing(method_name)
result = []
if @objects.any? { |obj| obj.class.method_defined? method_name }
@objects.each do |obj|
if obj.class.method_defined? method_name
result.push(obj.send(method_name))
end
end
else
raise NoMethodError
end
result
end
end
.F..

Failures:

  1) DrunkProxy proxies most of the methods
     Failure/Error: expect(proxy.class).to eq [string.class, array.class]
       
       expected: [String, Array]
            got: DrunkProxy
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -[String, Array]
       +DrunkProxy
     # /tmp/d20161215-15620-1ojik3o/spec.rb:19:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00474 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20161215-15620-1ojik3o/spec.rb:14 # DrunkProxy proxies most of the methods