Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Unicode在我的棋盘上弄乱了间距_Ruby_Unicode - Fatal编程技术网

Ruby Unicode在我的棋盘上弄乱了间距

Ruby Unicode在我的棋盘上弄乱了间距,ruby,unicode,Ruby,Unicode,unicode国际象棋棋子产生了一个奇怪的间距,并弄乱了棋盘的大小。我能用Ruby做些什么来解决这个问题吗 class GameBoard attr_accessor :white_king, :white_queen, :white_rook, :white_bishop, :white_knight, :white_pawn, :black_king, :black_queen, :black_rook, :black_knight, :black_bishop, :black_pa

unicode国际象棋棋子产生了一个奇怪的间距,并弄乱了棋盘的大小。我能用Ruby做些什么来解决这个问题吗

class GameBoard 
   attr_accessor :white_king, :white_queen, :white_rook, :white_bishop, :white_knight, :white_pawn, :black_king, :black_queen, :black_rook, :black_knight, :black_bishop, :black_pawn, :board 
      def initialize
      @white_king = "♔"
            @white_queen = "♕"
            @white_rook = "♖"
            @white_bishop = "♗"
            @white_knight = "♘"
            @white_pawn = "♙"
            @black_king = "♚"
            @black_queen = "♛"
            @black_rook = "♜"
            @black_bishop = "♝"
            @black_knight = "♞"
            @black_pawn = "♟" 
            @board = Array.new(8) { Array.new(8," ") }
            end
            def display
              @board.each { |i|
                print "\n"
                @a = "+----+----+----+----+----+----+----+----+"
                puts @a
                i.each {|n|
                  print "| #{n}  "
                  } 
                  print "|"}
                  print "\n"
                  print @a
            end 

            def knight 
              @board[0][0] = @black_knight
              display
            end 
    end 
    J = GameBoard.new
    J.knight
这是输出,骑士似乎占据了一个半空间。也许是一种改变ruby空间大小的方法

+----+----+----+----+----+----+----+----+
| ♞  |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+

Unicode还可以使用不同大小的空格

@board = Array.new(8) { Array.new(8,"  ") }
在声明数组中的第二个参数时使用这些空格而不是普通空格,使其与Unicode棋子的大小相同

U+0020  SPACE   foo bar     Depends on font, typically 1/4 em, often adjusted
U+00A0  NO-BREAK SPACE  foo bar     As a space, but often not adjusted
U+1680  OGHAM SPACE MARK    foo bar     Unspecified; usually not really a space but a dash
U+180E  MONGOLIAN VOWEL SEPARATOR   foo᠎bar     No width
U+2000  EN QUAD     foo bar     1 en (= 1/2 em)
U+2001  EM QUAD     foo bar     1 em (nominally, the height of the font)
U+2002  EN SPACE    foo bar     1 en (= 1/2 em)
U+2003  EM SPACE    foo bar     1 em
U+2004  THREE-PER-EM SPACE  foo bar     1/3 em
U+2005  FOUR-PER-EM SPACE   foo bar     1/4 em
U+2006  SIX-PER-EM SPACE    foo bar     1/6 em
U+2007  FIGURE SPACE    foo bar     “Tabular width”, the width of digits
U+2008  PUNCTUATION SPACE   foo bar     The width of a period “.”
U+2009  THIN SPACE  foo bar     1/5 em (or sometimes 1/6 em)
U+200A  HAIR SPACE  foo bar     Narrower than THIN SPACE
U+200B  ZERO WIDTH SPACE    foo​bar     Nominally no width, but may expand
U+202F  NARROW NO-BREAK SPACE   foo bar     Narrower than NO-BREAK SPACE (or SPACE)
U+205F  MEDIUM MATHEMATICAL SPACE   foo bar     4/18 em
U+3000  IDEOGRAPHIC SPACE   foo bar     The width of ideographic (CJK) characters.
U+FEFF  ZERO WIDTH NO-BREAK SPACE   foobar     No width (the character is invisible)

你不是只需要3个或5个水平插槽,而不是4个(这样你就可以将其居中)?我编辑了它,这样你就可以看到输出了。无论我做什么,间隔都会关闭。