scope

Scope Order by Count with Conditions Rails

穿精又带淫゛_ 提交于 2021-01-27 12:27:46
问题 I have a model Category that has_many Pendencies . I would like to create a scope that order the categories by the amount of Pendencies that has active = true without excluding active = false . What I have so far is: scope :order_by_pendencies, -> { left_joins(:pendencies).group(:id).order('COUNT(pendencies.id) DESC')} This will order it by number of pendencies, but I want to order by pendencies that has active = true . Another try was: scope :order_by_pendencies, -> { left_joins(:pendencies)

List comprehensions: different behaviour with respect to scope in debug mode and in normal runtime

落爺英雄遲暮 提交于 2021-01-27 05:40:15
问题 Consider the following: def f(): a = 2 b = [a + i for i in range(3)] f() This runs without problems. As I understand it (please correct me if I'm wrong, though), the list comprehension expression introduces a new scope, but since it is created within a function (as opposed to, say, a class), it has access to the surrounding scope, including the variable a . In contrast, if I were to enter debug mode, stop at line 3 above, and then just manually write the following in the interpreter >>> b =

List comprehensions: different behaviour with respect to scope in debug mode and in normal runtime

不羁的心 提交于 2021-01-27 05:39:25
问题 Consider the following: def f(): a = 2 b = [a + i for i in range(3)] f() This runs without problems. As I understand it (please correct me if I'm wrong, though), the list comprehension expression introduces a new scope, but since it is created within a function (as opposed to, say, a class), it has access to the surrounding scope, including the variable a . In contrast, if I were to enter debug mode, stop at line 3 above, and then just manually write the following in the interpreter >>> b =

What is the difference between scope and linkage?

白昼怎懂夜的黑 提交于 2021-01-27 05:23:04
问题 I tried different websites but I don't get it. Could you explain it in simple english? 回答1: "scope" is a namespace of the compiler; "linkage" is about compiled units. I explain a bit more: A variable declared in a function has the scope of that function, i.e. it is visible only within that function. A variable declared as static in a source file, can be seen only by the code in that source file (and all included files!). Variables can also have global scope: they can be referred to in a

What is the difference between scope and linkage?

て烟熏妆下的殇ゞ 提交于 2021-01-27 05:22:31
问题 I tried different websites but I don't get it. Could you explain it in simple english? 回答1: "scope" is a namespace of the compiler; "linkage" is about compiled units. I explain a bit more: A variable declared in a function has the scope of that function, i.e. it is visible only within that function. A variable declared as static in a source file, can be seen only by the code in that source file (and all included files!). Variables can also have global scope: they can be referred to in a

C++ template alias (using) in specific places

旧街凉风 提交于 2021-01-27 04:34:29
问题 I need to use type aliases via using (or any other method) in situations like this: template <class T> typename std::enable_if< /*HERE*/>::value f (...) {}; Where I wrote HERE there are long and more than one types defined inside structures, and instead of writing typename <very long templated struct dependent on T>::type I want to write a shortcut. And I encountered this in more situations like template specializations and suffix return type syntax. So Is there any way of using using (no pun

Why are bash variables not global if sourced script runs in a function?

北战南征 提交于 2021-01-22 18:06:12
问题 Sourcing a file normally from another script, I can access its variables. If I source a script from within a function, its variables aren't global, which seems to contradict the manpage: FUNCTION Variables local to the function may be declared with the local builtin command. Ordinarily, variables and their values are shared between the function and its caller. source filename [arguments] Read and execute commands from filename in the current shell environment Happens with all my conveniently

Why are bash variables not global if sourced script runs in a function?

会有一股神秘感。 提交于 2021-01-22 18:03:59
问题 Sourcing a file normally from another script, I can access its variables. If I source a script from within a function, its variables aren't global, which seems to contradict the manpage: FUNCTION Variables local to the function may be declared with the local builtin command. Ordinarily, variables and their values are shared between the function and its caller. source filename [arguments] Read and execute commands from filename in the current shell environment Happens with all my conveniently

Why are bash variables not global if sourced script runs in a function?

有些话、适合烂在心里 提交于 2021-01-22 18:02:06
问题 Sourcing a file normally from another script, I can access its variables. If I source a script from within a function, its variables aren't global, which seems to contradict the manpage: FUNCTION Variables local to the function may be declared with the local builtin command. Ordinarily, variables and their values are shared between the function and its caller. source filename [arguments] Read and execute commands from filename in the current shell environment Happens with all my conveniently

self. in trailing swift closures, meaning and purpose?

风格不统一 提交于 2021-01-20 08:00:32
问题 whenever I use a trailing closure on an action ... example: run(SKAction.wait(forDuration: 10)){timeRemains = false} I’m seeing this: Reference to property ( anything ) in closure requires explicitly ‘self’ to make capture semantics explicit. What does this mean? And what is it on about? I'm curious because I'm only ever doing this in the context/scope of the property or function I want to call in the trailing closure, so don't know why I need `self and fascinated by the use of the word