Решение на Втора задача от Йончо Йончев

Обратно към всички решения

Към профила на Йончо Йончев

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)

Код

require 'enumerator'
require 'Rational'
require 'Complex'
class Filter
def initialize
@list_numbers = []
end
end
class TypeFilter
# :integer, :real :complex
def initialize
@list_numbers = []
end
end
class SignFilter
# :positive, :non_positive, :negative , :non_negative
def initialize
@list_numbers = []
end
end
class NumberSet
include Enumerable, Comparable
attr_reader :list_numbers
def << element
if element.respond_to? :to_c
if ! list_numbers.include?(element)
@list_numbers.push element.to_c
end
else
raise "Not a number."
end
end
def <=>(other)
str.to_c <=> other.str.to_c
end
def size
return @list_numbers.size()
end
def empty?
return @list_numbers.empty?()
end
def each
@list_numbers.each { |i| yield i }
end
def initialize
@list_numbers = []
end
def include? element
@list_numbers.each do |i|
if i == element then true
end
end
return false
end
def []
end
end

Лог от изпълнението

/tmp/d20141028-18133-1v73bq8/solution.rb:2:in `require': cannot load such file -- Rational (LoadError)
	from /tmp/d20141028-18133-1v73bq8/solution.rb:2:in `<top (required)>'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:867:in `require'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:867:in `block in setup_load_path_and_require'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:867:in `each'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:867:in `setup_load_path_and_require'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration_options.rb:25:in `configure'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:21:in `run'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'

История (1 версия и 1 коментар)

Йончо обнови решението на 27.10.2014 12:08 (преди около 10 години)

+require 'enumerator'
+require 'Rational'
+require 'Complex'
+
+
+class Filter
+ def initialize
+ @list_numbers = []
+ end
+end
+
+class TypeFilter
+ # :integer, :real :complex
+ def initialize
+ @list_numbers = []
+ end
+end
+
+
+class SignFilter
+ # :positive, :non_positive, :negative , :non_negative
+ def initialize
+ @list_numbers = []
+ end
+end
+
+class NumberSet
+ include Enumerable, Comparable
+
+ attr_reader :list_numbers
+
+ def << element
+ if element.respond_to? :to_c
+ if ! list_numbers.include?(element)
+ @list_numbers.push element.to_c
+ end
+ else
+ raise "Not a number."
+ end
+ end
+
+ def <=>(other)
+ str.to_c <=> other.str.to_c
+ end
+
+ def size
+ return @list_numbers.size()
+ end
+
+ def empty?
+ return @list_numbers.empty?()
+ end
+
+ def each
+ @list_numbers.each { |i| yield i }
+ end
+
+ def initialize
+ @list_numbers = []
+ end
+
+ def include? element
+ @list_numbers.each do |i|
+ if i == element then true
+ end
+ end
+ return false
+ end
+
+ def []
+ end
+end