[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

AW: "require and subdirectories" problem

Recheis Meinrad

9/9/2003 2:07:00 PM

hi,
i found a hack like this and hoped that someone would come up with something more elegant
but, wow. this is definitely much dirtier.

this is my hack( according to my considered example):

in lib.rb:
$libpath=(__FILE__).sub Regexp.new(File.basename( __FILE__ ) ), ''

require $libpath+'annother.rb'


Von: Idan Sofer [mailto:idan@idanso.dyndns.org]

On Tuesday 09 September 2003 16:20, Recheis Meinrad wrote:
> hi,
> but i am not very pleased with it. the library in the directory lib, must
> not know from where it is required. what can i do so that lib can require
> all it's files no matter where the script that requires lib.rb is located?
One of the things I most like in Ruby, is that even core functionality can be
easily modified at run-time:

[start messy untested code]

alias :_oldrequire :require
def require(req)
if req=~/\//
splited=req.split('/')
req_file=splited.pop
req_path=splited.join('/')
oldpath=Dir.pwd
Dir.chdir req_path
ret=_oldrequire(req_file)
Dir.chdir oldpath
return ret
else
_oldrequire(req)
end
end

[end messy untested code]



2 Answers

colbertz

2/23/2009 8:49:00 AM

0

Hello Jakob,

Just need a little modification of your original LINQ codes. The following
has worked in my side.
using (PersonRolesDataContext dc = new PersonRolesDataContext())
{
var personRoles = dc.PersonRoles.Where(pr => pr.PersonID ==
1);

var allRoles = from r in dc.Roles
join pr in personRoles on r.RoleId equals
pr.RoleID into roleGroup
from g in roleGroup.DefaultIfEmpty()
select new {
r.RoleId,
r.RoleName,
Selected =(g==null?false:true)
};

allRoles.ToList();
}

Note in the select clause we need to use r.RoleId and r.RoleName instead of
g.RoleID, g.Role.RoleName. The latter one will cause the returned rows
include NULL. As a result, we meet the error mentioned in the first post.

And for the Selected column in the select clause, we need to test if it is
null. If yes, set the Selected to false, otherwise set it to true.

Please have a try and let me know if it works for you? Have a nice day!

Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

Jakob Lithner

2/23/2009 10:04:00 AM

0

Great !!!

The exchange of "g" with"r" in the select clause made the whole difference!

Thanks!