conditional-attribute

Ruby Conditional argument to method

隐身守侯 提交于 2019-12-12 01:50:01
问题 I have some 'generic' methods that extract data based on css selectors that usually are the same in many websites. However I have another method that accept as argument the css selector for a given website. I need to call the get_title method if title_selector argument is nos passed. How can I do that? Scrape that accept css selectors as arguments def scrape(urls, item_selector, title_selector, price_selector, image_selector) collection = [] urls.each do |url| doc = Nokogiri::HTML(open(url)

Does using ConditionalAttribute also remove arguments computation?

一个人想着一个人 提交于 2019-11-29 09:31:55
I tried the following code: class Magic { [Conditional("DEBUG")] public static void DoMagic( int stuff ) { } public static int ComputeMagic() { throw new InvalidOperationException(); } } class Program { static void Main(string[] args) { Magic.DoMagic(Magic.ComputeMagic()); } } and it looks like in Release build the exception is not thrown so not only the call to a method marked with ConditionalAttribute is removed, but also the parameters computation is eliminated. Is such behavior guaranteed? Yes, argument evaluation is removed when DEBUG is not defined (which is typical in Release builds).

Does using ConditionalAttribute also remove arguments computation?

一个人想着一个人 提交于 2019-11-28 03:16:20
问题 I tried the following code: class Magic { [Conditional("DEBUG")] public static void DoMagic( int stuff ) { } public static int ComputeMagic() { throw new InvalidOperationException(); } } class Program { static void Main(string[] args) { Magic.DoMagic(Magic.ComputeMagic()); } } and it looks like in Release build the exception is not thrown so not only the call to a method marked with ConditionalAttribute is removed, but also the parameters computation is eliminated. Is such behavior guaranteed