hierarchy

In Ruby, how does a class defined in a module know the module's constants?

寵の児 提交于 2019-12-03 17:24:05
I'm trying to understand how a class defined in a module knows the module's constants. Here's an example of what I mean: module Car class Wheel end class Seat p Wheel # Car::Wheel end end I know it's obvious, but since Wheel is nowhere in Seat's hierarchy, I don't understand how it can have access to it. If you reference a class constant, Ruby will look for it first in the same module, and then on the root if it's not found there. So, since both Seat and Wheel are in the Car module, if you look for Wheel , it will first look for Car::Wheel , and then for ::Wheel . Since Car::Wheel exists, you

Linq to Sql - Hierarchical Query to Find Ancestors

*爱你&永不变心* 提交于 2019-12-03 16:27:02
Given an EmployeeId, how can I construct a Linq to Sql query to find all of the ancestors of the employee? Each EmployeeId has an associated SupervisorId (see below). For example, a query of the ancestors for EmployeeId 6 (Frank Black) should return Jane Doe, Bob Smith, Joe Bloggs, and Head Honcho. If necessary, I can cache the list of all employees to improve performance. UPDATE: I've created the following crude method to accomplish the task. It traverses the employee.Supervisor relationship all the way to the root node. However, this will issue one database call for each employee. Anyone

Counting number of children in hierarchical SQL data

只愿长相守 提交于 2019-12-03 15:03:46
问题 for a simple data structure such as so: ID parentID Text Price 1 Root 2 1 Flowers 3 1 Electro 4 2 Rose 10 5 2 Violet 5 6 4 Red Rose 12 7 3 Television 100 8 3 Radio 70 9 8 Webradio 90 For reference, the hierarchy tree looks like this: ID Text Price 1 Root |2 Flowers |-4 Rose 10 | |-6 Red Rose 12 |-5 Violet 5 |3 Electro |-7 Television 100 |-8 Radio 70 |-9 Webradio 90 I'd like to count the number of children per level. So I would get a new column "NoOfChildren" like so: ID parentID Text Price

Drools - rule hierarchy and conditional execution

吃可爱长大的小学妹 提交于 2019-12-03 13:38:09
问题 I was wondering if there is a way to define hierarchy (not just order of execution) between rules and control the rule execution - i.e. if the parent rule fired then the ones below should not be evaluated etc... Information in this thread is an option but it is essentially IF/THEN/ELSE Is there a different option? thanks 回答1: I am not sure if I understand your question, but using a combination of Activation Groups and the traditional conflict resolution strategies might achieve what you need.

Select products where the category belongs to any category in the hierarchy

一个人想着一个人 提交于 2019-12-03 13:02:19
问题 I have a products table that contains a FK for a category, the Categories table is created in a way that each category can have a parent category, example: Computers Processors Intel Pentium Core 2 Duo AMD Athlon I need to make a select query that if the selected category is Processors, it will return products that is in Intel, Pentium, Core 2 Duo, Amd, etc... I thought about creating some sort of "cache" that will store all the categories in the hierarchy for every category in the db and

Creating Taxonomy Table in MySQL

对着背影说爱祢 提交于 2019-12-03 12:40:45
问题 I am creating a botanical database where the plants will be organized by their taxonomy: Life Domain Kingdom Phylum Class Order Family Genus Species I was considering using the example put forth by the article Managing Hierarchical Data in MySQL, however it is adding the above list as records inside the table....and I'm not sure if that is the best thing to do since I will be having multiple species per genus and multiple genus per family and so on. What would you suggest is the best way to

What's the best C# pattern for implementing a hierarchy with an enum?

笑着哭i 提交于 2019-12-03 12:37:26
I'm implementing value types which represents a distance (or length). There's an enum that represents the different units of measure, eg: public enum DistanceUnit { Millimeter, Centimeter, Meter, Kilometer, Inch, Foot, Yard, Mile }; These measurements fall into one of two systems - either metric or imperial. Since enum doesn't support hierachies, what's the best pattern for representing this hierarchy? Is it to use bit flags? Or use two seperate enums along with some methods to correlate them? Or to declare static members instead of enums? Give me some advice... how would you implement this?

Linq extension method, how to find child in collection recursive

对着背影说爱祢 提交于 2019-12-03 12:27:25
I'm already familiar with Linq but have little understanding of extension methods I'm hoping someone can help me out. So I have this hierarchical collection pseudo code ie: class Product prop name prop type prop id prop List<Product> children And I have a list of products List products. Is there any way I can look for product in this collection by the id with a extension method ? In other words I need one item somewhere within the hierarchy. Here is a generic solution that will short-circuit traversal of the hierarchy once a match is found. public static class MyExtensions { public static T

How to set parentViewController in UIViewController?

匆匆过客 提交于 2019-12-03 10:45:54
The parentViewController property of UIViewController is readonly, but I am nesting custom view controllers and would like to use this property. However, since it is readonly, and I found no other way to set this property, my quesion is: how do I set it? Obviously, UINavigationController can set the property somehow in -pushViewController, and so can -presentModalViewController, so it must be possible. I am aware that I can just add my own UIViewController property, but I'm sure that parentViewController is, in principle, the correct property. However, since it is readonly, and I found no

Clojure states within states within states

为君一笑 提交于 2019-12-03 10:40:38
I'd love to hear what advice the Clojure gurus here have about managing state in hierarchies. I find I'm often using {:structures {:like {:this {:with {:many 'levels}} } } } and if I want to track changes in state at multiple levels, by throwing atoms around values (atom {:like (atom 'this)} ) , I find myself thinking this must be wrong. Is it generally better to use just one atom at the top level, and have none as values in a map ? Don't use nested atoms in a data structure if at all possible. The main reason is that immutability is your friend. Clojure is a functional language that thrives