小编ast*_*nic的帖子

ruby将选定的整个单词括在括号中

@string = "Sometimes some stupid people say some stupid words"

@string.enclose_in_brackets("some") # => "Sometimes {some} stupid people say {some} stupid words"
Run Code Online (Sandbox Code Playgroud)

该方法应该如何包围_in_brackets?请记住,我只想附上整个单词,(我不想要"{Some}次{some}愚蠢....","有时"单词应保持不变

ruby regex string

1
推荐指数
1
解决办法
782
查看次数

Python替换Rubys grep?

abc=123
dabc=123
  abc=456
  dabc=789
    aabd=123
Run Code Online (Sandbox Code Playgroud)

从上面的文件我需要找到以abc =开头的行(空格无关紧要)

在ruby中我会把它放在一个数组中然后做

matches = input.grep(/^\s*abc=.*/).map(&:strip)
Run Code Online (Sandbox Code Playgroud)

我是Python中的一个完全noob,甚至说我是一个新的Python开发人员太多了.

也许有一个更好的"Python方式",甚至没有grepping?

我需要解决问题的平台上提供的Python版本是2.6

当时没有办法使用Ruby

ruby python

1
推荐指数
1
解决办法
193
查看次数

红宝石快速阅读标准

什么是从STDIN读取多个1000000个字符(整数)的最快方法,并将其拆分为一个字符整数(不是字符串)的数组?

123456 > [1,2,3,4,5,6]
Run Code Online (Sandbox Code Playgroud)

ruby performance refactoring profiling

0
推荐指数
1
解决办法
375
查看次数

填充稀疏数组

我有一个稀疏数组,例如:

rare = [[0,1], [2,3], [4,5], [7,8]]
Run Code Online (Sandbox Code Playgroud)

我想用这些数据绘制图表,每对都是点坐标.如你所见,我没有x = 1,x = 3,x = 5,x = 6的分数

我想用以前的值填充数组,所以对于上面的例子,我将得到:

filled = [[0,1], [1,1], [2,3], [3,3], [4,5], [5,5], [6,5], [7,8]
Run Code Online (Sandbox Code Playgroud)

如您所见,为了计算y值,我只需使用我使用的最后一个y值.

完成此任务的最佳方法是什么?

ruby arrays algorithm

0
推荐指数
1
解决办法
1168
查看次数

变量在部分中不可见

为什么title我的对象的属性page没有填充到标头模板中?

这是我的小程序

package main

import (
  "html/template"
  "os"
)

type Page struct {
  Title string
  Body  string
}

func main() {
  f, _ := os.Create("index.html")
  defer f.Close()

  page := Page{"I'm the title", "And I'm the body"}

  t := template.New("post.html")
  t = template.Must(t.ParseGlob("templates/*html"))
  t.Execute(f, page)
}
Run Code Online (Sandbox Code Playgroud)

这是 templates/post.html 文件:

{{template "header.html"}}
<article>
  {{.Body}}
</article>
{{template "footer.html"}}
Run Code Online (Sandbox Code Playgroud)

和我的 templates/header.html 文件:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>{{.Title}}</title>
  </head>
  <body>
Run Code Online (Sandbox Code Playgroud)

为了完整起见,我的页脚 templates/footer.html 文件:

<footer>
&copy; 2015
</footer>
</body>
</html> …
Run Code Online (Sandbox Code Playgroud)

templates go

0
推荐指数
1
解决办法
168
查看次数