class Fixnum
Public Class Methods
to_fixnum_html_table(from = 1, to = 100, return_num = 10)
click to toggle source
return value is fixnum table
Examples¶ ↑
1 to 30 by 10 case
Fixnum.to_fixnum_table(1, 30, 10)
result
<table> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td> <td>7</td> <td>8</td> <td>9</td> <td>10</td> </tr> <tr> <td>11</td> <td>12</td> <td>13</td> <td>14</td> <td>15</td> <td>16</td> <td>17</td> <td>18</td> <td>19</td> <td>20</td> </tr> <tr> <td>21</td> <td>22</td> <td>23</td> <td>24</td> <td>25</td> <td>26</td> <td>27</td> <td>28</td> <td>29</td> <td>30</td> </tr> </table>
1 to 10 by 2 case
Fixnum.to_fixnum_table(1, 10, 2)
result
<table> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> </tr> <tr> <td>7</td> <td>8</td> </tr> <tr> <td>9</td> <td>10</td> </tr> </table>
# File lib/open_classes/fixnum/to_fixnum_html_table.rb, line 84 def self.to_fixnum_html_table(from = 1, to = 100, return_num = 10) return '' unless from.is_a?(Fixnum) return '' unless to.is_a?(Fixnum) table_contents = [*from..to].each_slice(return_num).to_a.reduce([]) do |rets, row| rets << ' <tr>' rets << row.reduce([]) do |ret, column| ret << " <td>#{column}</td>" ret end.join("\n") rets << ' </tr>' rets end.join("\n") "<table>\n" + table_contents + "\n</table>\n" end
to_fixnum_table(from = 1, to = 100, return_num = 10)
click to toggle source
return value is fixnum table
Examples¶ ↑
1 to 100 by 10 case
Fixnum.to_fixnum_table(1, 100, 10)
result
| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| |11|12|13|14|15|16|17|18|19| 20| |21|22|23|24|25|26|27|28|29| 30| |31|32|33|34|35|36|37|38|39| 40| |41|42|43|44|45|46|47|48|49| 50| |51|52|53|54|55|56|57|58|59| 60| |61|62|63|64|65|66|67|68|69| 70| |71|72|73|74|75|76|77|78|79| 80| |81|82|83|84|85|86|87|88|89| 90| |91|92|93|94|95|96|97|98|99|100|
1 to 10 by 2 case
Fixnum.to_fixnum_table(1, 10, 2)
result
|1| 2| |3| 4| |5| 6| |7| 8| |9|10|
# File lib/open_classes/fixnum/to_fixnum_table.rb, line 39 def self.to_fixnum_table(from = 1, to = 100, return_num = 10) return '' unless from.is_a?(Fixnum) return '' unless to.is_a?(Fixnum) [*from..to].each_slice(return_num).to_a.to_table end