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)
|
||||
case printable(object)
|
||||
when :array then colorize("[...]", :array)
|
||||
when :hash then colorize("{...}", :hash)
|
||||
when :array then colorize("[...]", :array)
|
||||
when :hash then colorize("{...}", :hash)
|
||||
when :struct then colorize("{...}", :struct)
|
||||
else colorize("...#{object.class}...", :class)
|
||||
end
|
||||
|
@ -177,20 +177,16 @@ class AwesomePrint
|
|||
# Turn class name into symbol, ex: Hello::World => :hello_world.
|
||||
#------------------------------------------------------------------------------
|
||||
def declassify(object)
|
||||
if object.class.to_s.downcase =~ /^struct/
|
||||
result = :struct
|
||||
if object.is_a?(Struct)
|
||||
:struct
|
||||
else
|
||||
result = object.class.to_s.gsub(/:+/, "_").downcase.to_sym
|
||||
object.class.to_s.gsub(/:+/, "_").downcase.to_sym
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
# Pick the color and apply it to the given string as necessary.
|
||||
#------------------------------------------------------------------------------
|
||||
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?
|
||||
s
|
||||
else
|
||||
|
|
|
@ -292,8 +292,11 @@ EOS
|
|||
#------------------------------------------------------------------------------
|
||||
describe "Struct" do
|
||||
before(:each) do
|
||||
struct = Struct.new("SimpleStruct", :name, :address)
|
||||
@struct = struct.new
|
||||
@struct = unless defined?(Struct::SimpleStruct)
|
||||
Struct.new("SimpleStruct", :name, :address).new
|
||||
else
|
||||
Struct::SimpleStruct.new
|
||||
end
|
||||
@struct.name = "Herman Munster"
|
||||
@struct.address = "1313 Mockingbird Lane"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue