My classes can't use Shoes methods like para

纵然是瞬间 提交于 2019-12-02 03:52:12

I'm glad to see a question about shoes, it's been a long time. You'r new on SO so first: your question is way too elaborated, too much to read and far too little information to help you. You need to provide piecess of code that give error or don't do what you expect, things we can take over and try. This means extracting from your code tests or pieces of code that run by themself and show the problem.

We also need to know which Ruby version and which version and color of shoes you are using. The example I'll be using is green shoes.

I'm sure the following isn't exactly what you were after but I've made a sample based on your description of an Array that needs to be listed both by puts and para.

Change the question or make a new one if this is not what you are after.

require 'green_shoes'

s = Struct.new(:topic, :score)
s1 = s.new("test1", 1)
s2 = s.new("test2", 2)
A = [s1, s2]

class Array
  def putsdata(shoes = nil)
    if shoes.class == Shoes::App
      self.each do |ea|
        shoes.para "#{ea.topic}: #{ea.score}"
      end
    else
      self.each do |ea|
        puts "#{ea.topic}: #{ea.score}"
      end
    end
  end
end

A.putsdata

# gives in the console
# test1: 1
# test2: 2

Shoes.app do
  A.putsdata(self)
end

# gives in a graphic window
# test1: 1
# test2: 2

The puts also works in the shoes block, but of course the result doesn't come in the graphic window but on the console where you started, after the first list.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!