mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Avoid Struct redifinition warning when running specs; removed unnecessary code
This commit is contained in:
parent
ed177c0b10
commit
c9781fc974
2 changed files with 10 additions and 11 deletions
|
@ -161,8 +161,8 @@ class AwesomePrint
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def nested(object)
|
def nested(object)
|
||||||
case printable(object)
|
case printable(object)
|
||||||
when :array then colorize("[...]", :array)
|
when :array then colorize("[...]", :array)
|
||||||
when :hash then colorize("{...}", :hash)
|
when :hash then colorize("{...}", :hash)
|
||||||
when :struct then colorize("{...}", :struct)
|
when :struct then colorize("{...}", :struct)
|
||||||
else colorize("...#{object.class}...", :class)
|
else colorize("...#{object.class}...", :class)
|
||||||
end
|
end
|
||||||
|
@ -177,20 +177,16 @@ class AwesomePrint
|
||||||
# Turn class name into symbol, ex: Hello::World => :hello_world.
|
# Turn class name into symbol, ex: Hello::World => :hello_world.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def declassify(object)
|
def declassify(object)
|
||||||
if object.class.to_s.downcase =~ /^struct/
|
if object.is_a?(Struct)
|
||||||
result = :struct
|
:struct
|
||||||
else
|
else
|
||||||
result = object.class.to_s.gsub(/:+/, "_").downcase.to_sym
|
object.class.to_s.gsub(/:+/, "_").downcase.to_sym
|
||||||
end
|
end
|
||||||
result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Pick the color and apply it to the given string as necessary.
|
# Pick the color and apply it to the given string as necessary.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def colorize(s, type)
|
def colorize(s, type)
|
||||||
if type && !type.to_s.empty?
|
|
||||||
type = type.to_s.gsub(/^struct_.*/,'struct').to_sym
|
|
||||||
end
|
|
||||||
if @options[:plain] || @options[:color][type].nil?
|
if @options[:plain] || @options[:color][type].nil?
|
||||||
s
|
s
|
||||||
else
|
else
|
||||||
|
|
|
@ -292,8 +292,11 @@ EOS
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Struct" do
|
describe "Struct" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
struct = Struct.new("SimpleStruct", :name, :address)
|
@struct = unless defined?(Struct::SimpleStruct)
|
||||||
@struct = struct.new
|
Struct.new("SimpleStruct", :name, :address).new
|
||||||
|
else
|
||||||
|
Struct::SimpleStruct.new
|
||||||
|
end
|
||||||
@struct.name = "Herman Munster"
|
@struct.name = "Herman Munster"
|
||||||
@struct.address = "1313 Mockingbird Lane"
|
@struct.address = "1313 Mockingbird Lane"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue