您希望在Ruby on Rails中使用哪些功能,或者您发现哪些功能不完整或烦恼?
我有这样的代码:http://play.golang.org/p/aeEVLrc7q1
type Config struct {
Application interface{} `json:"application"`
}
type MysqlConf struct {
values map[string]string `json:"mysql"`
}
func main() {
const jsonStr = `
{
"application": {
"mysql": {
"user": "root",
"password": "",
"host": "localhost:3306",
"database": "db"
}
}
}`
dec := json.NewDecoder(strings.NewReader(jsonStr))
var c Config
c.Application = &MysqlConf{}
err := dec.Decode(&c)
if err != nil {
fmt.Println(err)
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么结果结构是空的.你有什么想法?
我有这样的代码:
package main
import "fmt"
type Foo struct {
foo_id int
other_id int
one_more_id int
}
type Bar struct {
bar_id int
}
func ids(???) []int { ??? }
func main() {
foos := {Foo{1},Foo{3}}
bars := {Bar{1},Bar{3}}
fmt.Println(ids(foos, ???)) // get foo_id
fmt.Println(ids(foos, ???)) // get other_id
fmt.Println(ids(foos, ???)) // get one_more_id
fmt.Println(ids(bars, ???)) // get bar_id
}
Run Code Online (Sandbox Code Playgroud)
我想制作ids
通用的,能够传递任何结构和某种方式(闭包?)和我需要检索的属性.这样做有意义吗?或许我应该使用不同的方法?
编辑:我的问题太暧昧,我必须清除它:
ids
函数应该能够从结构中获得多于一个字段,具体取决于需求,因为我更新了上面的代码.
我声明了简单的结构:
struct Heap {
int size;
int *heap_array;
};
Run Code Online (Sandbox Code Playgroud)
当我试图创建表时,k
stdin 中的int是:
Heap *rooms = new Heap[k];
Run Code Online (Sandbox Code Playgroud)
我有:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
Run Code Online (Sandbox Code Playgroud)
字面上使用int一切都很好:
Heap *rooms = new Heap[0];
Run Code Online (Sandbox Code Playgroud)
如何申报这样的表?
在课程期间https://class.coursera.org/reactive-001/class我遇到了这样的结构:
trait Generator[+T] {
def generate: T
}
Run Code Online (Sandbox Code Playgroud)
和用法:
val integers = new Generator[Int] {
val rand = new java.util.Random
def generate = rand.nextInt()
}
Run Code Online (Sandbox Code Playgroud)
为什么我们能做到这一点?哪里可以找到更多相关信息?
我需要在所有现有模型上禁用活动记录验证,是否有简单的方法来完成此操作?
编辑:因为我被警告不要在这里这样做,原因是:它在我的宠物项目中,其他人添加了验证,并且种子停止工作。由于每天晚上时间有限,我想编写代码,而不是专注于编辑非常复杂的种子。